user1058712
user1058712

Reputation: 417

Java makefile run

I have a project that I created with eclipse. Now I want to copy this project to my linux computer to compile and run it there.

For this I want to create a makefile for compiling and running automatically.

I already have created a makefile and it can compile my project. But now it should start my program after compiling and I dont know how to make this.

I want to type "make" and it should compile the source and after that it should start my main automatically. For now I have a shellscript that does the following.

make
java Main

I already tried to run "make run" but I get an error.

No rule to make target 'Main', needed by 'run'.

This is my Makefile.

JFLAGS = -g
JC = javac
JVM= java
FILE=
.SUFFIXES: .java .class
.java.class:
    $(JC) $(JFLAGS) $*.java
CLASSES = \
    Main.java \
    Class1.java \
    Class2.java \
    Class3.java \
    Class4.java

MAIN = Main

default: classes

classes: $(CLASSES:.java=.class)

run: $(MAIN).class
    $(JVM) $(MAIN)

clean:
    $(RM) *.class

Upvotes: 4

Views: 23347

Answers (1)

You need to add classes rather than Main.class as a dependency for run, since you haven't defined a rule for Main.class, i.e. this should work:

run: classes
    $(JVM) $(MAIN)

Upvotes: 4

Related Questions