How to set PATH and CLASSPATH in Windows 7?

How to set PATH and CLASSPATH in Windows 7?

If your source program (.java file) located in D: or somewhere else outside the bin directory of jdk and you want to compile and run the java program using javac and java respectively from that location then you must have to set following environment variable. The settings of environment variables in Windows 7 is similar to Windows XP but the way of finding Environment variable window is different. You can also use DOS ccommand to set these variables.

  • PATH
  • CLASSPATH

Here step by step guide is given to set above two environments variable in Windows 7 Operating System.

Step 1:

To set PATH variable copy the location up to bin directory located in java installation directory, In my machine java is installed in C:Program FilesJava so path for my machine is given below.

C:Program FilesJavajdk1.6.0_25bin

Step 2:

Right Click on My Computer and select Properties option.

Step 3:

Now you can see new window as shown below, in that click on Advanced System Setting option located on the top left corner of the window.

Step 4:

The Property Window get opened, in this window click on Environment Variables button.

When you click on Environment Variables. Now there are two categories for variables User Variables For <your computer name> which manages all user defined variable and second is System Variables.

You have to add two new variables PATH and CLASSPATH under User Variables. If variable with these names already exist then just edit it and add variable values at the end. If not exist then click on New and add variable details as given below.

 PATH variable details

            Variable Name : PATH

            Variable Value: C:Program FilesJavajdk1.6.0_25bin;

CLASSPATH variable details

            Variable Name : CLASSPATH

            Variable Value: C:Program FilesJavajdk1.6.0_25libtools.jar;

The CLASSPATH vale contains the path up to tools.jar java archive file which you find under lib directory inside the java/jdk1.6.0_25/ or whatever version of java development kit (jdk) you have installed.

Note: Don’t forgot to add semicolon (;) at the end of the variable value otherwise It will create a problem. 

How to check whether path and classpath are set appropriate or not?

Go to Run and type "cmd" and click on enter, now point your cmd (command prompt) to D:  and type javac  and press enter. If you get message as shown in below image then you have not set the path and classpath variables correctly.

If you get output as shown in below image then you have successfully set environment variables. Now you can compile and run java programs from any location.

SHARE

Related Tips