|
Think of it this way, PATH tells windows where to find executable files when one is typed on the command line. CLASSPATH does the same thing but for Java so it can find class files to run. There are two ways to set the CLASSPATH: 1. set the environment variable CLASSPATH and the second is to use the -cp option when running java. With that said if the CLASSPATH=c:\java;c:\myclasses, java will only look in those two locations for class files. OK that is not entirely true it will also look in JAVA_HOME/lib/ext but that is besides the point. Now with the above set say you are trying to run a program in c:\code\myproject and you have a class Test.class in that directory. Java will not find the Test class because it is looking at the CLASSPATH only. The current directory is not implied. If you want Java to find your class you must tell it where to look. The "-cp ." says, "Hey look in the current directory too". Some like to put the "." at the end of the CLASSPATH env variable like so "c:\java;c:\myclasses;."
The best solution is to have a build script that sets the CLASSPATH explicitly for your project as you compile and run it.
|