11 Sep 2013
Using WildCards for Resolving Classpath
In this post we shall learn using wildcards for resolving classpath, this is an interesting topic and very useful in case you are pro command line or non-GUI user.
I hope we are all familiar with running a Java Program from Command Line using java command.
1 |
java com.heapcode.main.TestMain |
Whenever the above Class TestMain.java needs additional dependent jars you have to manually list each jar on your Classpath such as:
1 |
java -cp lib/apache-collections.jar:lib/log4j.jar:/lib/hibernate3.jar com.heapcode.main.TestMain |
From Java versions 1.6 onwards a little known feature is that we can now use wildcards, so the above command becomes:
1 |
java -cp lib/*.jar com.heapcode.main.TestMain |
I hope this has been useful for you and I’d like to thank you for reading. If you like this article, please leave a helpful comment and share it with your friends.