CLASSPATH Explained
A Bit of Introduction
An environment variable is a bit of information maintained by the operating system that is available to every program. They are usually used to specify the location of important files that an application needs when it starts, or commonly used command line options. The CLASSPATH is such an environment variable. It is used by Java to locate the "class" files it needs to use. Depending on the operating system the environment variables may be set differently, and this is where most problems arise. Below is an attempt to render assistance to users with any Java supported platform.
Mac Users: DECAF will only run under MacOS X and higher. Since Mac OS X is at heart a flavor of UNIX, use the information in the that section.
UNIX
In UNIX the environment variables are set through the shell. Some shells sets these variables differently and when practical those differences are listed.
First, you might want to see if you already have a CLASSPATH variable defined and what is
in it. Do this type echo $CLASSPATH
at the prompt. There are three
possible outcomes. "CLASSPATH: Undefined variable." means that
no CLASSPATH variable is currently set up in the environment. A list of paths
separated by colons means a CLASSPATH has already been defined. If nothing is
printed except another command prompt, then that may mean that a CLASSPATH variable
has been created, but nothing is in it.
Now that you know whether or not you have a class path you need to know how to set it. This is where differences in the shell come in.
setenv CLASSPATH .:~/decaf_dir/decaf.jar:~/decaf_dir/planeditor.jar:$CLASSPATH
CLASSPATH=.:~/decaf_dir/decaf.jar:~/decaf_dir/planeditor.jar:$CLASSPATH
Some simple things to keep in mind:
:$CLASSPATH
if you already had a CLASSPATH. This
appends the previous CLASSPATH to your new one. This is important as other
programs might rely on the CLASSPATH as well.Windows
How you format and set the CLASSPATH on Windows machines is a little different then on UNIX. Go to Start→Control Panels→System and then click on the "Advanced" tab. Under Windows 2000 and XP there is a button at the bottom that says "Environment Variables". Select the button, a new window will open. There should be two lists, the top is User Variables and the bottom is System wide. Look in the variables at the top and see if CLASSPATH exists.
If you already have a CLASSPATH variable, select it and click on the "Edit" button. If
there is no CLASSPATH, then select the "New" button, and type CLASSPATH
as the name.
For the value you want to enter a period '.' as the first path. Then enter a semi-colon ';'
to separate between paths. Then enter either the directory where all the decaf files are located,
or the path with the jar file. If you are using decaf in the jar file, then the CLASSPATH must
include the name of the jar file, not just the enclosing directory. Next, enter another
semi-colon and the path to, and the name of, the planeditor jar file.
If there was already a CLASSPATH here then you will need another semi-colon, if not then you are done.