25

I have around hundreds of jars at a particular directory which my application uses. So I thought its hard to add each jars one by one to the classpath. So is there any command or any way so that i can add all the jars at one go. some *.jar should add all the jars.

skaffman
  • 398,947
  • 96
  • 818
  • 769
GuruKulki
  • 25,776
  • 50
  • 140
  • 201
  • An example would be to add "...\java_project\jar\*;" to your classpath. The important part is that after the name of the folder, you include the backslash and the star. – xxjjnn Feb 02 '13 at 17:45

1 Answers1

25

Yes, you can use a wildcard, as of Java6. See the section on "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.

Prior to Java 6, you had to specify them all individually.

Qtax
  • 33,241
  • 9
  • 83
  • 121
skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 7
    That's right, as long as you are using "the CLASSPATH environment variable" or "the -classpath (or -cp) command-line option". The pain starts when using a MANIFEST.MF: "However, class path wildcards are not honored in the Class-Path jar-manifest header." – bobndrew Jun 01 '11 at 11:08
  • doesn't work for me, windows 10, also tried "foo/*" and foo/"*" – Genry Apr 16 '17 at 14:52