Fortunately, if you're using Java2 (JDK1.2 or higher) you probably don't need a classpath environment variable at all. At least, if you do need one, that's probably because you've been writing Java for a while and are doing something complicated - in which case you can probably avoid most of the pitfalls on your own.
Java2 VMs look for classes in three places - the
bootclasspath which by default contains rt.jar and i18n.jar
(for 1.2.2 and 1.3.1 - it looks like for 1.4 the latter will become
charsets.jar), the extensions
directories and the general classpath. It is the last one which
is affected by the CLASSPATH environment variable or specifying
-classpath on the command line.
When using extra libraries, it's probably easiest to use the extensions mechanism (follow link above for more information and gotchas) to show the VM where the libraries are. In the common case of then just having one place where other classes are kept (ie one directory structure with your freshly compiled classes), the default value of the classpath is fine - it's just the current directory. Just stick to the guidelines about compiling and running and you should manage easily.
-classpathflag or by setting the CLASSPATH environment variable. In this case, you may well want to include the absolute directory names so that you can be in either tree to run your app. I would strongly urge you not to go changing the classpath unless you really have to though. It's caused a lot of grief to a lot of people in the past.
Back to the main page.