How do I compile a java file that has jar dependen

2019-01-11 23:18发布

问题:

I have a helper lib that I wrote to sit on top of Apache Commons, and when I try to javac it (so that I can make it into a jar) it complains, quite reasonably, that it has no idea what I'm talking about when I make reference to the stuff that's in the commons.jar.

How does one include a jar so as that javac can compile?

回答1:

For windows:

javac -cp ".;/dir/commons.jar;/dir/more_jar_files.jar" MyClass.java

For unix or mac (thanks for the tip Dawood):

javac -cp ".:/dir/commons.jar:/dir/more_jar_files.jar" MyClass.java

Which means:

javac -cp <path to jar> MyClass.java


标签: java jar javac