Is there a way to include all the jar files within a directory in the classpath?
I\'m trying java -classpath lib/*.jar:. my.package.Program
and it is no
We get around this problem by deploying a main jar file myapp.jar
which contains a manifest (Manifest.mf
) file specifying a classpath with the other required jars, which are then deployed alongside it. In this case, you only need to declare java -jar myapp.jar
when running the code.
So if you deploy the main jar
into some directory, and then put the dependent jars into a lib
folder beneath that, the manifest looks like:
Manifest-Version: 1.0
Implementation-Title: myapp
Implementation-Version: 1.0.1
Class-Path: lib/dep1.jar lib/dep2.jar
NB: this is platform-independent - we can use the same jars to launch on a UNIX server or on a Windows PC.