Java makefile dont execute run command

I create one makefile in my project.

JFLAGS = -g JC = javac JVM= $(JAVA_HOME)/bin/java .SUFFIXES: .java .class .java.class: ; $(JC) $(JFLAGS) $*.java CLASSES = \ Class1.java \ Class2.java \ Main.java MAIN = Main default: classes classes: $(CLASSES:.java=.class) run : classes $(JVM) $(MAIN).class 

The codes below start and compile my java class, but do not execute my start command. finish creating the file and do not execute my run. Why is this wrong in my code?

+4
source share
2 answers

You need to add the run command as an action of the run target, and not a necessary condition:

 run : classes $(JVM) $(MAIN) #make sure the line above begins with a tab 
+3
source

Make will try to create the first target in your makefile (and all the premises of this target and all the premises of these goals, etc.). To select another or more than one top-level goal (or "goal target"), you can specify them on the command line: make run .

You can transfer the run target as the first target in the makefile, then it will run by default.

Or, if you have more than one β€œtop level” goal that you want to run, you can assemble them in another rule; for example, in the above example you can use:

 default: classes run 

Although, by a long-standing agreement, this goal is called all (but it's just an agreement).

0
source

Source: https://habr.com/ru/post/1502879/


All Articles