Monday, 12 September 2011

Easy classpaths with Java 6

Back in the day it used to be a bit more difficult than it is now to dynamically generate your java application classpath - you'd have to write a script to loop over all the jar files in a directory, appending them to your classpath variable - like this.

Since Java 6 though, its been a lot easier - you can use wildcards to specify all jars in a directory. See the "Understanding class path wildcards" in the Java SE 6 documentation.

Now its as simple as:

java -cp /my/lib/dir/* MyClass

Simple! As it should be!