Reputation: 1479
I'm trying to compile .java
files and store them in a sub-directory called bin
. I then want to run the generated .class
files from the main directory. How can I do this?
Here's my Makefile:
# java compiler
JCC = javac
# output directory
OUTDIR = bin/
# compilation flags
JFLAGS = -g -d $(OUTDIR)
# default target entry
default: A.class B.class C.class
A.class: A.java
$(JCC) $(JFLAGS) A.java
B.class: B.java
$(JCC) $(JFLAGS) B.java
C.class: C.java
$(JCC) $(JFLAGS) C.java
# To start over from scratch, type 'make clean'.
# Removes all .class files, so that the next make rebuilds them
clean:
$(RM) $(OUTDIR)*.class
What I want to do:
Upvotes: 1
Views: 1288
Reputation: 1484
You must specify the bin
directory as the classpath of the JVM, using the -cp
option
java -cp bin A
A
being the fully qualified name of the class to run.
Upvotes: 2