If you want to add all the JARs in directory to the classpath, you can do this concisely using classpath wildcard syntax; for example:
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.
- Classpath wildcards were first introduced in Java 6. Earlier versions of Java do not treat "*" as a wildcard.
- You cannot put other characters before or after the ""; e.g. "someFolder/.jar" is not a wildcard.
- A wildcard matches only files with the suffix ".jar" or ".JAR". ZIP files are ignored, as are JAR files with a different suffixes.
- 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 is not specified.