views:

533

answers:

5

G'day everybody, 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?. Any suggestions would be much appreciated. Thanks.

Paul.

A: 

Why don't you clean up your mess by moving the REQUIRED jar files into a single folder and set the classpath to the folder? ;)

Chathuranga Chandrasekara
Well that's exactly what i did but i have been using the wildcard wrongly (%PATH%/*.jar instead of %PATH%/*).
paulbullard
+1  A: 

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

Itay
I found the same link a bit too late ;). Thanks anyway.
paulbullard
TFM says that you cannot do this in Java 1.5 or earlier.
Stephen C
A: 

Wow.I found the solution at http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html by googling. Silly me. :p Guess i should have searched that first.

paulbullard
A: 

Basename wild cards were introduced in Java 6; i.e. "foo/*" means all ".jar" files in the "foo" directory.

In earlier versions of Java that do not support wildcard classpaths, I have resorted to using a shell wrapper script to assemble a Classpath by 'globbing' a pattern and mangling the results to insert ':' characters at the appropriate points. This would be hard to do in a BAT file ...

Stephen C
+1  A: 

If you mean that you have an environment variable named CLASSPATH, I'd say that's your mistake. I don't have such a thing on any machine with which I develop Java. CLASSPATH is so tied to a particular project that it's impossible to have a single, correct CLASSPATH that works for all.

I set CLASSPATH for each project using either an IDE or Ant. I do a lot of web development, so each WAR and EAR uses their own CLASSPATH.

It's ignored by IDEs and app servers. Why do you have it? I'd recommend deleting it.

duffymo