java -classpath *.jar

It’s quite annoying that you cannot use wildcards in the -classpath command line option to java and javac. Quite often you want to include all .jar files in one directory.

Here is a way to get that effect:

java -classpath `echo lib/*.jar | sed -e “s/ /:/g”`

You can even include all .jar files in a whole hierarchy of directories:

java -classpath `find repository -name *.jar -printf %p:`

In general it’s better to use Ant or Maven for compiling and Java Service Wrapper for running, they have built-in support for wildcards. But they require some upfront setup, so my solution is useful for ad-hoc usage.

This works in Linux and probably in Solaris and other UNIX systems. If you use Windows, you need to install cygwin or similar.

This entry was posted in Java. Bookmark the permalink.

2 Responses to java -classpath *.jar

  1. I’m truly enjoying the design and layout of your blog.

    It’s a very easy on the eyes which makes it much more enjoyable for me to come here
    and visit more often. Did you hire out a designer to create your theme?

    Exceptional work!

  2. I am using a standard WordPress theme, “Twenty Ten”.

Comments are closed.