Search code examples
javajarjavac

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?


Solution

  • 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