From: http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html

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.

This should work in Java6, not sure about Java5

(If it seems it does not work as expected, try putting quotes. eg: "foo/*")

Answer from Itay Maman on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 6 › docs › technotes › tools › windows › classpath.html
Setting the class path
If the CLASSPATH variable is set at system startup, the place to look for it depends on your operating system: 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.
🌐
Gradle
discuss.gradle.org › help/discuss
How to use wildcards in JavaExec classpath - Help/Discuss - Gradle Forums
April 2, 2015 - So I have a folder that has manu jar files. And I have to use these jar files in classpath for java exec task. But it gives me - What went wrong: Execution failed for task ‘:TestProj:runTest’. A problem occurred starting process 'command ‘C:\Program Files\Java\jdk1.6.0_31\bin java.exe’' Caused by: java.io.IOException: CreateProcess error=206, The filename or extension is too long I am doing something like def jarFiles = files { file('testDir').listFiles() } task runTest(type: JavaExec) {...
🌐
Rip Tutorial
riptutorial.com › adding all jars in a directory to the classpath
Java Language Tutorial => Adding all JARs in a directory to the...
A wildcard matches only JAR files in the directory itself, not in its subdirectories. When a group of JAR files is matched by a wildcard entry, their relative order on the classpath ...
🌐
Blogger
javarevisited.blogspot.com › 2012 › 10 › 5-ways-to-add-multiple-jar-to-classpath-java.html
5 ways to add multiple JAR in to Classpath in Java - Examples
August 31, 2021 - These were a couple of ways you can include JAR files in your Classpath. Java 6 wildcard is the preferred way of adding multiple JAR in classpath along with the –cp and –classpath command-line option.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › tools › windows › classpath.html
2 Setting the Class Path
April 21, 2026 - The sh, ksh shells: Examine your .profile file for the export command. Class path entries can contain the base name wildcard character (*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR.
Find elsewhere
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8222160
wild-cards are broken in the java.class.path in JDK 11
REGRESSION : Last worked in version 11.0.2 STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : two ways mkarra@bldlinux10a testjdk]$ $JDKDIR/bin/java -cp $NOTESBIN/* lotus.domino.console.DominoController -jc -s -c Error: Could not find or load main class .home.mkarra.sandboxes.testjdk.bin.linux64.bin.AddMembers Caused by: java.lang.ClassNotFoundException: .home.mkarra.sandboxes.testjdk.bin.linux64.bin.AddMembers OR swap a specifying a single jar in the classpath with * as shown below strncpy(classpath, "-Djava.class.path=", sizeof(classpath)-1); strcat(classpath, exedir); strcat(classpath, DIR_SEPARATO
🌐
sqlpey
sqlpey.com › java › java-classpath-wildcards-multiple-jars
Java Classpath Wildcards: How to Include Multiple JARs Efficiently
July 22, 2025 - Often, these libraries are packaged as JAR files, and including many of them individually in the classpath can be cumbersome. Fortunately, Java provides wildcard support for the classpath, allowing you to include all JARs within a directory with a single entry.
🌐
Colin.java
colinchjava.github.io › 2023-10-01 › 18-34-22-741044-using-wildcards-in-the-java-classpath
Using wildcards in the Java CLASSPATH
September 30, 2023 - In this example, lib/* matches any jar file or directory within the lib directory and adds them to the classpath. It effectively includes all jars in the lib directory without explicitly listing each one. Wildcards can also be used to match partial file or directory names.
🌐
Piotrnowicki
piotrnowicki.com › java classpath and wildcards
Java classpath and wildcards | Piotr Nowicki's Blog
May 19, 2011 - Pretty useful thing about the Java classpath definition is that the wildcard (*) can be used in a replacement of all *.jar and *.JAR files in the specified directory. So the following line: java -cp /tmp/app/*:/tmp/myJar.jar com.nullhaus.MyApp will add the /tmp/myJar.jar to the classpath, as well as all the *.jar and *.JAR files in the /tmp/app directory.
🌐
GitHub
github.com › SpencerPark › IJava › issues › 17
Can't use wildcards in IJAVA_CLASSPATH option · Issue #17 · SpencerPark/IJava
May 22, 2018 - "IJAVA_CLASSPATH" : "/path/to/lib/Lib1.jar:/path/to/lib/Lib2.jar:/path/to/lib/Lib3.jar" However, it is possible to use wildcards in Java classpaths to point to multiple .jar files in one directory.
Author   SpencerPark
🌐
CodingTechRoom
codingtechroom.com › question › how-to-use-wildcards-java-classpath
How to Use Wildcards to Simplify Your Java Classpath for Multiple JAR Files? - CodingTechRoom
Create a script to dynamically generate your CLASSPATH by reading all JAR files in a target directory. Use the Java -cp (or -classpath) option with a wildcard when executing your Java program, but make sure to use the correct syntax for your ...
🌐
Bug Database
bugs.java.com › bugdatabase › view_bug.do
Bug ID: JDK-7146424 Wildcard expansion for single entry classpath
FULL PRODUCT VERSION : java version ... Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows XP [Version 5.1.2600] A DESCRIPTION OF THE PROBLEM : Wildcard expansion doesn't work correctly for -classpath (-cp) parameter ...
🌐
Apache JIRA
issues.apache.org › jira › browse › DAEMON-453
[DAEMON-453] Add support for wildcard classpath in java mode - ASF Jira
For windows, in javajni.c, line 915-920 looks like a good place to call the __apxEvalClasspath which expands any wildcard paths into a complete list. if (szClassPath) { p = (LPWSTR)apxPoolAlloc(hPool, (lstrlenW(JAVA_CLASSPATH_W) + lstrlenW(szClassPath)) * sizeof(WCHAR)); lstrcpyW(p, JAVA_CLASSPATH_W); lstrcatW(p, szClassPath); (*lppArray)[i++] = p; }
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-7146424
[JDK-7146424] Wildcard expansion for single entry classpath
FULL PRODUCT VERSION : java version "1.7.0_03" Java(TM) SE Runtime Environment (build 1.7.0_03-b05) Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows XP [Version 5.1.2600] A DESCRIPTION OF THE PROBLEM : Wildcard expansion doesn't work correctly for -classpath (-cp) parameter when only one entry is specified.