Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!
  • 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
  • Piet Souris

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: and 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 ]
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Low Tech Laboratory
    Bookmark Topic Watch Topic
  • New Topic