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.
精彩评论