Using wildcards in java classpath [duplicate]

The java classpath wildcard expansion is unusual.

From the docs:

Understanding class path wildcards

Class path entries can contain the basename wildcard character *, which is considered equivalent to
specifying a list of all the files in the directory with the extension
.jar or .JAR. For example, the class path entry foo/* specifies all
JAR files in the directory named foo. A classpath entry consisting
simply of * expands to a list of all the jar files in the current
directory.

So, what you need to specify is:

java -classpath /path/to/app/conf/lib/*:/path/to/app/lib/*

If you need only specific jars, you will need to add them individually. The classpath string does not accept generic wildcards like nameJar*, *.jar, spring* etc.

Read Setting multiple jars in java classpath for more information.

Leave a Comment