It’s quite annoying that you cannot use wildcards in the
-classpath command line option to
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”` org.foo.MyApp
You can even include all
.jar files in a whole hierarchy of directories:
java -classpath `find repository -name *.jar -printf %p:` org.foo.MyApp
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.