Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a wildcard in the classpath to add multiple jars? [duplicate]

I have been using so many 3rd party libraries(jar files) that my CLASSPATH is completely messed up as i have to include the path for every single jar file that i use.

I've been wondering if there is a way to include all the jar files in a folder using wildcard(*) operator (like *.jar). But it seems to be not working. Is there any other way that can shorten the CLASSPATH that currently looks like an essay ;) on my PC?.

like image 248
paulbullard Avatar asked Aug 06 '09 05:08

paulbullard


People also ask

How do I include jar name in CLASSPATH environment variable?

The CLASSPATH variable contains a list of directories where class files are found. A . jar file is really a zipped up directory, so the name of the . jar file itself should be in the CLASSPATH, not the name of the directory it is in.

How do I find the CLASSPATH of a jar file?

To check our CLASSPATH on Windows we can open a command prompt and type echo %CLASSPATH%. To check it on a Mac you need to open a terminal and type echo $CLASSPATH.


1 Answers

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/*")

like image 94
Itay Maman Avatar answered Sep 21 '22 07:09

Itay Maman