• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Class Path

Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Iam Facing problem i dont know how to set class path? and why we need class path.
plz solve my problem
keep the peace
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following explanation will work on WINDOWS environment.
If you have to set the classpath do the following steps...
1. Locate the directory where your java executables are existing (For eg. the default directory when you install will be c:\j2sdk1.4.0
If you are using some other version of java then that path like c:\jsdk1.2.0 )
2. Once you have located the path write it down in a piece of paper for easy reference.
3. Open Autoexec.bat file which is located in your C:\ drive. If it is not there create one.
4. In that give the following lines.
5. Save your autoexec.bat file.
6. Reboot(Restart the system)
Now this will define the classpath.
Why classpath is needed???
To run the application java needs to know where the bin and include libraries are located. To compile your application or to run your application java needs libraray and include files.
By defining the classpath you are showing executables located in the specific directory
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mohammad,
As Leela says, the path needs to reference the directory where the java binaries are located, i.e. if java was installed in C:\java\jdk1.3.1_05 then you PATH environment variable must include the C:\java\jdk1.3.1_05\bin directory.
But I guess your question was more related to the class path.
The class path tells the JVM where to locate the classes that needs to be loaded. These classes might be in a specific directory or in a library. The CLASSPATH environment variable can be set to set these locations.
Alternatively you may use the -classpath command line option when running the java executable.
For instance, if your classes are in the default package (without any package declaration), you have to specify the directory where these files reside in the classpath.
Example 1:
Calculator.java and Key.java are the files of my java application and are stored in the c:\calc\ directory.
To run my Calculator application, after compiling the classes, I use the following command:

Example 2:
Now I have improved my calculator and I store the configuration file in a XML file. I now use a library named xerces.jar than I stored in the c:\calc\lib directory.

Java will treat the xerces.jar component as a directory (same as c:\java, i.e. it expects to find classes inside the archive.
Example 3:
Now my application has evolved and for clarity reasons, I am using various packages.
First, I moved all my java files in the c:\java\src directory. Then I have created three packages com.mycompany.calc, com.mycompany.calc.config and com.mycompany.calc.gui, and so the files for each packages are stored in the following directories:
* c:\calc\src\com\mycompany\calc
* c:\calc\src\com\mycompany\calc\config
* c:\calc\src\com\mycompany\calc\gui
I have decided (again for clarity) to store the class files in the c:\calc\classes directory. To do so, I compile my java files with the following command:

Once done, all I have to do to run my Calculator application is:

Hope this helps
[ December 03, 2002: Message edited by: Beno�t d'Oncieu ]
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic