简体   繁体   中英

Reference all jars from a folder

I'm executing a java application in DOS command window using something like

java -cp abcclient.jar;junit-4.4.jar;myapp.jar MyMainClass

I need to reference many other jars that are found in a specific folder outside my application folder. Is there anyway I could state a folder name in the above command line to let java refer to the necessary jars from that folder.

Thanks

With java6, you can use a wildcard in classpath entries, so:

java -cp "abcclient.jar;junit-4.4.jar;myapp.jar;..\lib\*" MyMainClass

should work

(There's some problems explained here though http://javahowto.blogspot.com/2006/07/jdk-6-supports-in-classpath-but-be.html )

The very simplest way to do it is with the extensions mechanism:

java -Djava.ext.dirs=lib MyMainClass

For javac, the equivalent is the -extdirs flag:

javac -extdirs lib MyMainClass.java

It's not ideal - particularly if you also want to use the normal extensions - but it can be a useful little shortcut in some cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM