Adding multiple jars to classpath on commandline [

2019-01-24 21:32发布

This question already has an answer here:

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 ?

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-24 21:47

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
查看更多
姐就是有狂的资本
3楼-- · 2019-01-24 21:53

ClassPath set through command prompt will work only for current cmd window. Once you close it and open a new cmd window it will not work. Rather than setting classpath from command prompt, keep related paths to system properties:

For windows:

go to My Computer--> Properties--> Advance System Settings--> Environment Variables--> CLASSPATH--> put your path like this--> path1;path2;path3;. Don't forget to keep . (DOT) at the end.

查看更多
登录 后发表回答