Script to build a Java classpath

If you need to compile or run Java programs from the command line, it can be a real hassle to identify all the jar libraries the program requires and include them in your classpath.

Here is a short script that will do this work for you on Unix, Linux or Mac systems. It finds all the jar files in the current directory or its subdirectories, and merges the list into a classpath string delimited by colon (

:

) characters.

export CP=`find . -name '*.jar' | tr "\n" :`

You can then run your program like so:

java -classpath $CP MyProgram
This entry was posted in Coding, Tips. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>