Java classpath and wildcards

Pretty useful thing about the Java classpath definition is that the wildcard (*) can be used in a replacement of all *.jar and *.JAR files in the specified directory. So the following line: java -cp /tmp/app/*:/tmp/myJar.jar com.nullhaus.MyApp will add the /tmp/myJar.jar to the classpath, as well as all the *.jar and *.JAR files in the /tmp/app directory. Just remember that classpath never works recursively, so if you want to scan a subdirectory for jars you need to point it explicitly....

May 19, 2011 · 1 min