PDA

View Full Version : Java CLASSPATH ?



Z.K.
May 1st, 2011, 01:34 AM
I entered echo $CLASSPATH from the command line and received a blank line. I did not actually print a path of any kind or give an error. Does this mean the CLASSPATH is not set and if so how do I set it properly?

:?

NovaAesa
May 1st, 2011, 03:10 AM
You are correct, this means it's not set. To set, use:

export CLASSPATH=/path/to/wherever

Z.K.
May 1st, 2011, 03:51 AM
You are correct, this means it's not set. To set, use:

export CLASSPATH=/path/to/wherever

Thanks, that is what I thought.

jespdj
May 4th, 2011, 10:08 PM
It's better not to set a global CLASSPATH environment variable, because it affects all Java programs that you'd run on your computer.

Instead, use the -cp option on the command line to specify the classpath for the program you're running. For example:

java -cp myproject/classes org.myproject.MyProgram

(where your compiled *.class files are in the directory myproject/classes).

Kelvari
September 3rd, 2011, 05:27 PM
You are correct, this means it's not set. To set, use:

export CLASSPATH=/path/to/wherever

I tried that, and there was no change in the $CLASSPATH command. Should it be run with sudo to set it, or is there something else that I need to do? I'm asking as I need to have a specific .jar file for a class in school, and can't even compile my assignments if I can't get Java to recognize the .jar file.

dwhitney67
September 3rd, 2011, 06:28 PM
I tried that, and there was no change in the $CLASSPATH command. Should it be run with sudo to set it, or is there something else that I need to do? I'm asking as I need to have a specific .jar file for a class in school, and can't even compile my assignments if I can't get Java to recognize the .jar file.

Why not employ jespdj's advice, and use the -cp option when you are compiling your code?

Something like:


javac -cp /path/to/specific.jar App.java