For the benifit of those not familiar with environment variables, they are instructions to the operating system, or other programs telling them where they can find certain resources they may need.
Most systems with have a PATH variable, when you type the name of a program at the command prompt, or when a program tries to execute another program internally, the operating system needs to know where to look to find that program. The PATH variable contains a list of directories for the operating sytem to look in.
Likewise, with the CLASSPATH, when you run a Java program, the JVM needs to know where the class files are saved.
Often these will be in the current working directory, but sometimes, you want to be able to use classes from somewhere else.
Note: When adding a jar file to the CLASSPATH, you must include the the name of the jar file, not just its path.
For example, if you have some classes in C:\Classes then you should add C:\Classes to your CLASSPATH, but if you have a jar file called C:\Classes\MyJar.jar then you must add C:\Classes\MyJar.jar.
Therefore, if you want to add both the classes in the directory and the jar file, then you should add both paths to your CLASSPATH.
Setting the CLASSPATH, is System dependant.
Here I will tell you how to set the CLASSPATH on various Windows versions.
UNIX instructions will follow when I find out how to do it properly.
Once you have set the CLASSPATH, you can check that you did it correctly by opening up a command prompt and typing
![]()
echo %classpath%
You should then hopefully see your classpath printed out on the screen.
Windows XP/2000
- Right-click on My Computer and choose Properties.
- Click on the Advanced tab, then click Environment Variables
- If Windows will let you, then I recomend setting the
CLASSPATHas a system variable, but if you don't have administrator priveledges, then you will need to set it as a user variable. The procedure is the same, you just have to make sure you are looking at the right group of buttons. - In the Variable column, look for
CLASSPATH. If you can see it, select it, the click Edit, otherwise click new. - In the Name box enter

CLASSPATH - If you are creating the classpath, then in the value box enter

.(a full stop, or period).
- Now enter a semi-colon (;) followed by the path you want to add, for example

;C:\My Documents\System\Libraries - Your
CLASSPATHshould now look something like this:
.;path1;path2 - Click Ok on all dialog boxes.
- Any command prompts that were open before you made the changes, will need to be closed before they will acknowledge the changes.
Windows ME
- Click Start --> Programs --> Accessories --> System Tools, then select Sytem Information.
- Click Tools, the select System Configuration Utility.
- Go to the Environment tab
- In the Variable column, look for
CLASSPATH. If you can see it, select it, the click Edit..., otherwise click new... - In the Name box enter

CLASSPATH - If you are creating the classpath, then in the value box enter

.(a full stop, or period).
- Now enter a semi-colon (;) followed by the path you want to add, for example

;C:\My Documents\System\Libraries - Your
CLASSPATHshould now look something like this:
.;path1;path2 - Click Ok on all dialog boxes.
- Restart your computer
Windows 9x
- Open up My Computer then double click on the C: drive.
- Right click on AutoExec.bat and select Edit
- Look for a line that begins

set CLASSPATH= - If it is not there, then type it yourself
- After that type (if it is already there, anywhere in that line, then don't bother)

.(a full stop, or period).
- Now at the end of the line enter a semi-colon (;) followed by the path you want to add, for example

;C:\My Documents\System\Libraries - The line should now look something like this:

set CLASSPATH=.;path1;path2 - Save the file
- Restart your computer










