Setting Java classpath option with spaces and quotes under Windows® - Digizol6

Post Top Ad

Responsive Ads Here

Post Top Ad

Monday, December 18, 2006

Setting Java classpath option with spaces and quotes under Windows®

Responsive Ads Here
Java provides two methods for setting paths of the classes.
1. Set the command line option classpath
2. Set the CLASSPATH environment variable

The second option is easy, but has a draw back as a common CLASSPATH is shared within all the projects and classes, which makes it harder to test different projects with different classes.

So the first option is the prefered way. It is used as;
java -classpath first.jar;second.jar TestClient

classpath
When the paths to the jar files have spaces, the command line classpath option causes errors. Under Windows installation like 2000/NT/XP, all the users get a folder with the user name under a folder named "Documents and Settings" (which has a space). And if the jar files are under the user folder, path would look like "C:/Documents and Settings/someUser/.." which would cause the above error.

How to over come this issue
1. Put quotes and group the whole class path
java -classpath "C:/Documents and Settings/user/project/lib/axis.jar; C:/Documents and Settings/user/project/lib/axis-ant.jar;" TestClient

2. Put quotes on individual paths
java -classpath "C:/Documents and Settings/user/project/lib/axis.jar"; "C:/Documents and Settings/user/project/lib/axis-ant.jar;" TestClient

5 comments:

  1. blank

    Both options didn't work for me....

    ReplyDelete
  2. blank

    Let us know how you are trying to set the classpath; then we'll work it out.

    ReplyDelete
  3. blank

    If you can't get option 2 (quotes around individual paths) to work, make sure you don't have a space after the semi-colon. This was the case for me at least. For example:

    Correct:

    java -classpath "classpath1";"classpath2" Foo

    Incorrect:

    java -classpath "classpath1"; "classpath2" Foo

    ReplyDelete
  4. blank

    Really helpful.
    i was looking for overcome that error.
    it works.thanks.

    ReplyDelete
  5. blank

    You can also use a combination of both
    i.e.
    javac -classpath path1;path2;"%CLASSPATH%" MyClass.java

    This method did not work for me until I came to the realization that CLAPPSATH is NOT the same as CLASSPATH.

    Dyslexia's a btich!

    ReplyDelete

Post Top Ad