Adding multiple jars to classpath on commandline
12,700
Remove the spaces from the classpath and add the current path
javac -cp jar/A.jar:jar/B.jar:jar/C.jar:jar/D.jar:. MyFile.java
Since Java 6 you can use classpath wilcards
javac -cp jar/*:. MyFile.java
Author by
user3044327
Updated on June 11, 2022Comments
-
user3044327 almost 2 years
I'm running Ubuntu and want to execute a Java file from terminal by including multiple jar files.
All my jars are included in tha jar folder.
I tried
javac -cp jar/A.jar: jar/B.jar: jar/C.jar: jar/D.jar MyFile.java
I get below error.
javac: invalid flag: jar/B.jar: Usage: javac <options> <source files> use -help for a list of possible option
Can anyone guide how to use multiple jars in classpath ?
-
user3044327 about 10 yearsand what about if I have to execute the classfile??
-
Reimeus about 10 yearsThe same classpath will work for the JVM
-
user3044327 about 10 yearsThanks. Works like a magic.
-
Peter over 5 yearsSpecifying application specific jars on system level is not a way to go. This is why startup scripts exist which are often a mess, but more flexible.
-
Vallerious over 3 yearsWhat if I want to include a jar and another custom class in the same directory as my Main.java file? I tried
javac -classpath ./guava-18.0.jar:. Main.java
but it does not find the custom class. -
Reimeus over 3 yearstry
javac -classpath ./guava-18.0.jar:. *.java