0

How can I add two or more jar file in the compile step using cmd?

using one jar file:

javac -g -cp YOUR_JAR.jar YOUR_FILE_NAME.java

Any ideas how to compile two jar files?

2 Answers2

1

You can do that using the -classpath flag.

javac -classpath your.jar:my.jar ...

The delimiter between jars changes according to your platform.

You can read about that by running javac -help or reading the javac documentation online and About Setting the Class Path.

You will notice there that the documentation says:

Multiple path entries are separated by semicolons with no spaces around the equals sign (=) in Windows and colons in Oracle Solaris.

So, all Xnix operating systems use a : as delimiter, whereas Windows use a ;.

Edwin Dalorzo
  • 76,803
  • 25
  • 144
  • 205
0

As far as I understand, your question is about using multiple jars as the classpath when compiling java source code.

To use multiple jar/classpath files when compiling, you should separate them by your target platforms path separator, this is ';' on windows, and ':' on linux, example:

javac -g -cp FIRST.jar;SECOND.jar MY_FILE_NAME.java    (windows)
javac -g -cp FIRST.jar:SECOND.jar MY_FILE_NAME.java    (linux)

Sources: Including jars in classpath on commandline (javac or apt) (java and javac have the same classpath parsing

Community
  • 1
  • 1
Ferrybig
  • 18,194
  • 6
  • 57
  • 79