If I have
CLASSPATH=/blah;/foo
Then run
java -cp bar.jar com.yourcompany.SomeMain
Is the classpath now
bar.jar
OR is it
/blah;/foo;bar.jar
Basically does the command line switch override or augment the existing CLASSPATH
?
Looks like the -cp option overrides the CLASSPATH environment variable.
$ export CLASSPATH=Tests
$ java Printf
Team Name No. of Wins No. of Losses
Bobcats 0 0
Tigers 1 1
Lions 2 2
Cheetahs 3 3
Jackals 4 4
Leopards 5 5
Snow Leopards 6 6
Cougars 7 7
Mountain Lions 8 8
Bobcats 9 9
$ java -cp . Printf
Error: Could not find or load main class Printf
The CLASSPATH environment variable is still set to the folder Tests, however, when I use the -cp
option it overrides it, and changes the classpath to .
, the current directory, so my class file can no longer be found.
yes!, the cp or classpath option overrides the system variable. for more information
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html
The -cp command line switch overrides. In fact, a few other things override the CLASSPATH environment variable like the -jar switch, or IDE-specific classpath settings.
In any case, if you want to have a quick look at which classpath gets referenced when running your code, you can consider displaying this line in your class.
System.getProperty("java.class.path");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With