Yevgeny Simkin
Yevgeny Simkin

Reputation: 28349

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

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?

Upvotes: 22

Views: 60746

Answers (1)

zengr
zengr

Reputation: 38899

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

Upvotes: 57

Related Questions