Does java --classpath override CLASSPATH or append to it?

classpath, java

Solution

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.

Problem

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`?

Original source

Related problems