Home » Java » Makefile with Java-Exceptionshub

Makefile with Java-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


I realize the make isn’t the best tool to be using with Java, but I just wanted to experiment with it. I have this script but I’m not sure why it isn’t working:

JC = javac
.SUFFIXES:  .java .class
    $(JC) $(JFLAGS) $*.java

$(SRC_DIR)/Fibonacci_Methods.java \
$(SRC_DIR)/Fibonacci_Methods_Test.java \

default: classes


    $(RM) *.class

I get this error:

make: /path/to/make_test/Fibonacci_Methods.class: No such file or directory
make: *** [classes] Error 1

I’m not sure why. My understanding is that this script should define CLASSES, which should call .java.class target because I’m defining files ending with .java. I don’t know the purpose of $(CLASSES:.java=.class) because I would have thought the compilation be done already before this step.

I have not yet compiled the java code, by the way (so I’m running make with .java files only, if that makes a difference).

How to&Answers:

This is wrong:


Here you’ve defined a target with no prerequisites and recipe (which is supposed to be a command that is used to rebuild the target) that consists of a list of .class filenames, so you’re getting the error you see because you can’t “run” a list of .class files.

You want this:


which defines a target classes with a set of prerequisites which are the .class files you want to build, and no recipe because you don’t want to create a target named classes.