Will the use of -classpath
option with java
, add to or replace the contents of the CLASSPATH
env variable?
views:
397answers:
4
A:
Yes. Quoted from the java(1)
man page:
-classpath classpath
-cp classpath
Specifies a list of directories, JAR archives, and ZIP archives to search for class files. Class
path entries are separated by colons (:). Specifying -classpath or -cp overrides any setting of the
CLASSPATH environment variable.
If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the cur-
rent directory (.).
Robert Munteanu
2010-01-29 11:11:52
The environment variable is *not* updated at all, according to this. I don't see how the answer is "yes".
S.Lott
2010-01-29 11:14:42
@S.Lott - From whose point of view? From the *program's* point of view the CLASSPATH value (if it exists) is replaced. From the *shell's* point of view the CLASSPATH value isn't changed. I think the original question was just badly worded.
Nate
2010-01-29 13:49:29
+3
A:
Either one of the options is used, not both.
Specifying -classpath or -cp overrides any setting of the CLASSPATH environment variable.
...
The -classpath option is preferred because you can set it individually for each application without affecting other applications and without other applications modifying its value.
...
Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.
The MYYN
2010-01-29 11:12:15
+2
A:
Using the classpath variable it overrides the CLASSPATH of Environment variable but only for that session. If you restart the application you need to again set the classpath variable.
giri
2010-01-29 14:13:04