I've searched around for answers and alas have come here to ask. What is my best option for getting the make error "make: Nothing to be done for 'default'." for the java project that I am doing.
I've made sure that my indents are correct and I've tried "make clean" and "make default". I am also editing and running this with cygwin on a windows machine, but I am not using anything else but cygwin to create, edit, and run the makefile. I also have the latest java version installed.
Here's my provided makefile
JFLAGS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
ALU.java \
Binary_Debugger.java \
CreateSim.java \
Data.java \
IF.java \
IssueUnit.java \
MEM.java \
Pc.java \
PostALU.java \
PostMem.java \
Pre_Issue_Buffer.java \
PreALU.java \
PreIssue.java \
PreMEM.java \
PrintCycle.java \
Register.java \
Write_Back_Unit.java \
main.java
default: classes
classes: $(CLASSES: .java=.class)
clean:
$(RM) *.class
I expect for a .jar file to be compiled, but I just get this error.
That means your classes already exist (therefor nothing is to be done). If you want to rebuild anyway, do a make clean first. Like,
make clean
make
As for jar'ing your compiled classes, you have no jar target.
Related
I'm building a java program in Windows envoirment, but i need to be able to compile it in Linux envoirment. I'm currently having problems with the makefile:
the project folders are organized in this way:
project_folder
library.jar
src
folder1
a.java
b.java
folder2
c.java
d.java
folder3
e.java
The e.java file into folder3 is in almost all the others .java files because it's the principal struct, and for every file i have the line
import folder3.e;
Wich Eclipse automatically generates when i use a structure from another class file. What the terminal tells me:
error: Package folder3 does not exist
this is the makefile
JFLAGS = -g -cp library.jar -sourcepath .
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
src/folder1/a.java \
src/folder1/b.java \
src/folder2/c.java \
src/folder2/d.java \
src/folder3/e.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
find . -name "*.class" -type f -delete
It's my very first makefile for java and i think i'm wrongly including the references between classes, how i can solve this?
Thank you
UPDATE: #Karthikeyan Vaithilingam thank you for your detailed answer, now it's all clear and working!
Add -d . to JFLAGS so the class files will be created with proper folder structure.
So your JFLAGS should be as follows.
JFLAGS = -g -cp .:library.jar -sourcepath . -d .
-d is the flag is used for destination folder in the above example its the current folder. You can use any destination but don't forget to add it to the classpath using -cp. By using -d you can keep the source folders clean, also cleaning will be easy, just remove the destination folder.
Update
The problem is the order of the Java files in CLASSES section. Since folder3.e class is referred in other classes it has to be at the beginning. It should be like the below one.
CLASSES = \
src/folder3/e.java \
src/folder1/a.java \
src/folder1/b.java \
src/folder2/c.java \
src/folder2/d.java
Also you can keep the libraries in a separate folder then use -cp libs\* to add all the jars in the folder. It will be easy to maintain
So the folder structure will be
project_folder
libs
library.jar
src
folder1
a.java
b.java
folder2
c.java
d.java
folder3
e.java
And the final Makefile will be
JFLAGS = -g -cp ".:libs/*" -sourcepath . -d .
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
src/folder3/e.java \
src/folder1/a.java \
src/folder1/b.java \
src/folder2/c.java \
src/folder2/d.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
rm -r folder*
Unrelated
Why don't you use build tools Gradle or Maven or Ant?
I need to make a makefile to compile a couple of my java files to turn in but I have no idea how to do that. I searched the web with no luck. Currently my file is
JFLAGS = -g
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = \
Proj411.java \
ExecTime.java \
Clocks.java \
Instruction.java \
simulator: Proj411.java
Proj411.java: ExecTime.java Clocks.java Instruction.java
clean:
$(RM) *.java
I want to make sure this is doing what I want it to do. Proj411 is where my main is located and it is dependent on the three other files to run.
Also on a side note, any explanation on what a makefile actually does may help. Thanks
Java projects are usualy built with either Ant- or Maven- skripts, and are a bit more comfortable than the Makefile (-horror).
So try to move to ant, or maven. Ant may be a bit simpler.
I think you have to add the following line to your makefile:
classes: $(CLASSES:.java=.class)
Also, if you want to be able to just type "make" at the command line instead of "make simulator" you should add:
all: simulator
My makefile is below
Also, I would appreciate it if you told me how to move my .class files to ../bin/
JFLAGS = -cp
JAR = "RSBot*.jar"
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $(JAR) $*.java
CLASSES = \
src/Banker.java \
src/Eater.java \
src/Fighter.java \
src/grotgui.java \
src/InventTab.java \
src/Looter.java \
src/Potter.java \
src/W8babyGrotworm.java \
src/Walker.java
default: classes
classes: $(CLASSES:.java=.class)
clean:
$(RM) *.class
As you can see here, How to wildcard include JAR files when compiling?, you cannot use the wildcard '*' in the classpath to get several jar files unless you are using java 1.6 or above. Otherwise, you should write each concrete jar you need.
To put your .class files in the bin directory, you can use the -d <directory> option of javac to specify where to place generated class files.
just out of curiosity, why make? why not use a more modern tool like maven, ant or gradle?
They are designed for this sort of thing and usually give you what you want out of the box.
But to answer your question:
javac -d outputdir
For a homework assignment I have to make a makefile (physically and in software) for a series of .java files that I have written.
I have written up a make file:
JFLAGS = -d -g bin/
JC = javac
.SUFFXES: .java .class
CLASSES = \
cdn\communications\CommandReader.java \
cdn\communications\CommandReaderFactory.java \
cdn\communications\CommandReaderThread.java \
cdn\communications\DiscoveryCommandReader.java \
cdn\communications\Link.java \
cdn\communications\RefreshThread.java \
cdn\communications\RouterCommandReader.java \
cdn\node\Discovery.java \
cdn\node\Node.java \
cdn\node\Router.java \
cdn\utility\Utility.java \
cdn\wireformats\DeRegisterRequest.java \
cdn\wireformats\DeRegisterResponse.java \
cdn\wireformats\LinkInfo.java \
cdn\wireformats\LinkWeightUpdate.java \
cdn\wireformats\MessageType.java \
cdn\wireformats\PeerRouterList.java \
cdn\wireformats\RegisterRequest.java \
cdn\wireformats\RegisterResponse.java \
cdn\wireformats\RouterInfo.java \
cdn\wireformats\WireFormatFactory.java \
all : $(CLASSES)
clean : $(CLASSES:.java=.class)
But when I run it I get the message "make: Nothing to be done for `all'." and none of my files are made.
Is there something I'm missing here? I'm running the file from the directory that holds the "cdn" directory hierarchy?
Any thoughts would be appreciated.
You have not specified how to build the java classes in your Makefile. Essentially something like below...
.java.class:
$(JC) $(JFLAGS) $*.java
Refer to this link which has a good example.
Fix your all target to depend on .class files instead of .java files (that are already exist and thus " Nothing to be done").
all : $(CLASSES:.java=.class)
Also, you have to a add a rule to compile .java files into .class files:
%.class : %.java
$(JC) $(JFLAGS) $<
In case of using the rule above (so-called pattern rule), .SUFFXES: isn't needed anymore, you can remove it at all.
As outlined by others above, you can easily do something like this:
%.class : %.java
javac flags_go_here
... but there's a few problems with this:
If there are any dependencies between classes -- and there will be -- you'll have to get the order right. There aren't any tools or command-line options like what GCC provides for generating dependencies for you
Java allows circular dependencies between classes. It isn't possible to compile two classes that depend on each-other unless you compile them together, eg:
${JAVAC} ${FLAGS} class1.java class2.java
javac has a long start-up time. For small projects you won't notice it, but for any project where there's enough classes it'll add up fast, and your build times go downhill fast.
The best solution I've come up with is something like the following (using GNU-make style syntax):
all: my.jar
my.jar : c1.java c2.java ... cN.java
${JAVAC} ${JAVAC_FLAGS} ${^}
${JAR} cf ${JAR_FLAGS} ${#} -C src ${^:%.java=%.class}
# As a bonus, here's how you could do JNI stuff based on individual class files.
# This is necessary because nothing in the build actually depends directly on
# the .class files; if they don't exist and the .jar does, then you need some
# way to get the .class files without rebuilding the jar.
# It's written this way so it's re-usable.
# I'm using 'unzip' instead of 'jar' because it has the -j option so it won't
# dump some/irritating/path/to/work/with/when/all/I/need/is/the/.class/file
define CANNED_JAVAH_TARGET =
$(if $(filter %.java,${^}),,\
$(error When building ${#}: No jar dependency provided))
unzip -j -d /somewhere/to/put/temp/class/file \
$(filter %.jar,${^}) ${PKG_PATH}/${#F:%.h=%.class}
${JAVAH} ${JAVAH_FLAGS} <whatever flags are needed to make the header>
endef
${JNI_HEADER_TARGETS} : my.jar
${CANNED_JAVAH_TARGET}
There is a problem with the javah portion: for the JAVAH thing, if someone makes it depend on more than one jar, it'll break. There may be a few minor mistakes or things to work around in the above (going from memory here), but all in all it has worked for me without much hassle.
I need to make a makefile that compiles and executes my classes with an external jar file..
I have 4 classes;sync.java, FileSynchroniser.java, DirectoryTracer.java and SyncFileTracer.java.
I also need to include gson-1.7.1.jar ..
Heres my make file
.SUFFIXES: .class .java
JAVAC= $(JAVAHOME)\bin\javac
PATH=$(JAVAHOME)\bin;$(PATH)
CLASSPATH=.;$(JAVAHOME)\lib\classes.zip;$(JSDKHOME)\lib\classes.zip
DEST=.
DOC=.
JAVA=$(JAVAHOME)\bin\java
JAVACFLAGS=-deprecation
.SUFFIXES: .java .class
.java.class:
$(JAVAC) -classpath $(CLASSPATH) $(JAVACFLAGS) $<
CLASSFILES = sync.class \
FileSynchroniser.class \
DirectoryTracer.class \
SyncFileTracer.class
SOURCEFILES = sync.java \
FileSynchroniser.java \
DirectoryTracer.java \
SyncFileTracer.java
# begin ---- JAR support ----------
JARFILE= gson-1.7.1.jar
$(JARFILE): $(CLASSFILES) $(SOURCEFILES)
jar cfm0 $(JARFILE) <<manifest.tmp $(CLASSFILES)>>
# end ---- JAR support ----------
all : $(JARFILE) $(CLASSFILES) doc
doc : $(CLASSFILES)
javadoc -version -author -d $(DOC) $(SOURCEFILES)
install :
copy $CLASSESFILE $(DEST)
clean:
del $(CLASSFILES)
Thank you
Are you referring to making the makefile in a Linux OS?
Check this - make makefile guide
http://www.cs.swarthmore.edu/~newhall/unixhelp/howto_makefiles.html
or this - example
http://www.cs.swarthmore.edu/~newhall/unixhelp/javamakefiles.html
hope it help.