CLASSPATH Problems

If you get any message like this,

$ java HelloWorld
Can't find class HelloWorld

it probably means your CLASSPATH environment variable isn't properly set up. Make sure it includes the current directory as well as the location where the classes.zip file was installed. On Unix it should look something like this:

CLASSPATH=.:/usr/local/java-1.1/lib

Under Windows it will probably look something like this

C:\JDK\JAVA\CLASSES;c:\java\lib\classes.zip

Under Unix you set CLASSPATH variables like this:

You'll probably want to add one of these lines to your .login or .cshrc file so it will be automatically set every time.

Under Windows you set the CLASSPATH environment variable with a DOS command like

C:\> SET CLASSPATH=C:\JDK\JAVA\CLASSES;c:\java\lib\classes.zip

You can also add this to your autoexec.bat file (Windows ME and earlier) or set it in the environment variables tab of the System control panel (Windows NT and later) You should of course point it at whichever directories actually contain your classes.

The CLASSPATH variable is also important when you run Java applets, not just when you compile them. It tells the web browser or applet viewer where it should look to find the referenced .class files. If the CLASSPATH is set improperly, you'll probably see messages like "Applet could not start."

If the CLASSPATH environment variable has not been set, and you do not specify one on the command line, then Java sets the CLASSPATH to the default:

Here . is the current directory and $JAVA is the main Java directory where the different tools like javac were installed.


Previous | Next | Top | Cafe au Lait

Copyright 1997-2006 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified April 5, 2006