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 not able to find class files that are certainly in those jars. Do I need to add each jar file to the classpath separately?
Best Answer
Using Java 6 or later, the classpath option supports wildcards. Note the following:
"
)*
, not*.jar
Windows
Unix
This is similar to Windows, but uses
:
instead of;
. If you cannot use wildcards,bash
allows the following syntax (wherelib
is the directory containing all the Java archive files):(Note that using a classpath is incompatible with the
-jar
option. See also: Execute jar file with multiple classpath libraries from command prompt)Understanding Wildcards
From the Classpath document:
Note: due to a known bug in java 8, the windows examples must use a backslash preceding entries with a trailing asterisk: https://bugs.openjdk.java.net/browse/JDK-8131329