Monday, July 4, 2011

Wildcard in Java classpath

One of the less known new features of JDK 6 is the ability to use wildcards in classpaths.
That means that instead of doing…
java -cp lib\x.jar;lib\y.jar;lib\z.jar; com.company.MyProggy
…you could just do…
java -cp lib\*.jar; com.company.MyProggy
That generally turns out to be quite a time saver. Especially so if you are trying out something at a remote box and vi is your only editor.
However, if you use the wild card, there is no way to predict the order in which the jars will be used. In some cases, the order is important – and in those cases, you will need to add in the jars like one normally does by enumerating each one explicitly.
Also, don’t forget the semi colon at the end of the classpath. Sometimes lots of time is lost due to this. It can be really frustrating!

No comments:

Post a Comment

Chitika