简体   繁体   中英

How do I add a .jar file to the compilation of .java files

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM