Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compile a java file that has jar dependencies?

Tags:

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?

like image 766
Yevgeny Simkin Avatar asked Feb 01 '12 06:02

Yevgeny Simkin


1 Answers

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
like image 52
zengr Avatar answered Oct 18 '22 08:10

zengr