Dynamically generating the Java Classpath within a shell script

One of the main maintenance issues with running a Java application from a shell script is keeping your classpath up-to-date with the new and updated jars. To make things more difficult you can’t specify a folder as the classpath as it doesn’t include the jars in it only .class files. However through the use of a basic for loop we are able to dynamically generate the classpath.

CP=
for i in `ls ./lib/*.jar`
do
  CP=${CP}:${i}
done
// Java // Tips & Tricks // Unix //

Comments & Questions

Add Your Comment