Java Language Adding all JARs in a directory to the classpath


Example

If you want to add all the JARs in directory to the classpath, you can do this concisely using classpath wildcard syntax; for example:

 someFolder/*

This tells the JVM to add all JAR and ZIP files in the someFolder directory to the classpath. This syntax can be used in a -cp argument, a CLASSPATH environment variable, or a Class-Path attribute in an executable JAR file's manifest file.See Setting the Class Path: Class Path Wild Cards for examples and caveats.

Notes:

  1. Classpath wildcards were first introduced in Java 6. Earlier versions of Java do not treat "*" as a wildcard.
  2. You cannot put other characters before or after the ""; e.g. "someFolder/.jar" is not a wildcard.
  3. A wildcard matches only files with the suffix ".jar" or ".JAR". ZIP files are ignored, as are JAR files with a different suffixes.
  4. A wildcard matches only JAR files in the directory itself, not in its subdirectories.
  5. When a group of JAR files is matched by a wildcard entry, their relative order on the classpath is not specified.