Path

Setting the PATH Statement

The PATH statement is used by DOS and Windows to determine where to look for programs.

When you run a program from the command window (sometimes called the DOS window), DOS looks in the current folder for the program. If it can't find the program, it looks inside each folder listed in the PATH statement. If the program is not found in any of these folders, DOS displays the error message "Bad command or file name".

This page describes how to change the PATH statement so DOS can find your programs no matter what directory you are currently in.


If you are using Windows 2000 or XP

Use Explorer to find exact name of folders where the Java SDK is installed. View of SDK from Explorer

 

My Computer Icon

 

Right mouse click on My Computer
Select Properties from the menu

 

Select the Advanced tab.

Click on the Environment Variables button near the bottom of the window.

 

 

My Computer Properties Dialog Box
Click on image for a larger view.

 

Environment Variable Dialog Box
Click on image for a larger view.

 

 

Scroll down until you find the PATH variable.

Click on the EDIT button.

Add the following to the path to the bin (binary) directory. Use semicolon ";" to separate items:

;C:\j2sdk1.4\bin

Important Note: This must match the address that you determined in the first step, Finding the SDK with Explorer. This path statement will be different on different computers.

 

To verify your settings

Open a DOS command window (Start/Run/Command)

Type in the command: set

Look at the PATH variable to see if the path includes the Java SDK

 

 

DOS Command Window - SET
Click on image for a larger view.


If you are using Windows 95-98

(1) Find where the program is located on the hard drive.

Let's say you want to run the program named JAVADOC.EXE.
You can do a search (Start/Search/Files & Folders) to find that it is located in a directory C:\JBuilder6\jdk1.3.1\bin as shown in the graphic from Windows Explorer shown below.

View of Directory Structure

 

(2) View your current PATH to see if that directory is included.

To view the current path, open up a command window (Start/Run/command)

Type in "SET" at the DOS prompt.

This will show all of the environment variables. Stay focused on the PATH statement and look for the directory your program is located in. Notice in this example that there is a listing for C:\JBuilder6\jdk1.3.1 . However, this won't work because the JAVADOC.EXE program is in the bin directory of this folder.

Don't let the other variables bother you. Stay focused on the PATH statement.

Command Window showing original PATH statement

(3) Modify the Autoexec.bat file to add to the PATH

An easy way to change the PATH statement is to use the SYSEDIT program (Start/Run/Sysedit). Be patient, it takes awhile on some systems to display.

The REM statement is a remark telling others what the next line does.
The PATH keyword sets the PATH environment variable.
Each directory that should be search is typed on the line, separated by semicolons (;).
The %PATH% will add this folder to the existing PATH statement. (PATH statements can also be set when you do a network login as part of the login script.)

Please note: The name of the directory MUST be spelled correctly. Open up Windows Explorer and go to the file so you have a reference to look at as you type in the SYSEDIT program.

When you close SYSEDIT it will ask you if you want to save. Answer YES.

Very Important! After you save the file, you have to do a complete shut down. On some systems (Windows 2000), doing a warm boot will not cause the AUTOEXEC.BAT file to run and the changes you've made won't happen.

View of SysEdit program

 

(4) Double check the PATH statement.

Repeat step number 2 and look at the PATH statement:

Command Window showing correct PATH statement

You should be able to run the program once you see the correct directory in the PATH statement.

To test your path, open up a command window (or use the current one) and type in just the program name. In this case, JAVADOC. You should see the program start and a long series of help statements showing what should go on the command line when you run this program.

If the error messages still say that the file cannot be found, go back and double check the directory (step 1) as well as the spelling of the directory (step 2).

****

The CLASSPATH environment variable is not the same as the PATH.
PATH is used by DOS to locate an executable program to run.
CLASSPATH is used by Java to locate compiled classes located on the hard drive.