Posts Tagged classpath

How to set PATH and CLASSPATH in Java

When we write a java program and put the source file(.java file) in a location other than
bin of jdk, java compiler can not find the necessary class files of java api(as java.lang.*,
for example) to compile our file.So we need to set PATH and CLASSPATH environment variables
in our system. Here are the steps:

Adding Path:
1. Go to my computer
2.Right click, go to properties.
3. Go to Advanced tab.
4. Go to Environment Variables tab.
5. Search for PATH, then click on edit.
6. Add the path of your JDK bin folder, as C:\Program Files\Java\jdk1.5.0_15\bin
7. Click OK.

Adding Classpath:

1. Go to my computer
2.Right click, go to properties.
3. Go to Advanced tab.
4. Go to Environment Variables tab.
5. Search for CLASSPATH, then click on edit.
6. If it is not there, then add it by clicking NEW.
7. Add the path of your JDK lib folder, as C:\Program Files\Java\jdk1.5.0_15\lib
7. Click OK.

By these steps,we can execute javac command under any directory in our system.
After these steps, open a new cmd prompt window, and compile your program, as:
C:\Documents and Settings\chirag.jain\Desktop>javac Program.java

After compilation, run the program as:

C:\Documents and Settings\chirag.jain\Desktop>java Program

Advertisements

Leave a comment