Nov 22, 2012

Classpath settings in java


Notes on changing CLASSPATH

If you are using an IDE, the IDE might be doing the work of setting up your CLASSPATH, so you might not have had to deal with it.
The CLASSPATH is an environment variable.  The exact method of setting and changing it is system dependent.  In Windows 98, it gets set in your autoexec.bat using a line of the form
SET CLASSPATH=dir1;dir2;dir2;dir4
In Windows/NT, you can set the CLASSPATH from the control panel's System panel.  In Unix, you would normally set it from your profile (e.g. .profile or .cshrc file.)  If you are not sure, ask someone familiar with your operating system regarding the method of setting or changing it.  An example of an autoexec.bat line to set classpath is
SET CLASSPATH=C:\MyJspClasses;C:\ThirdPartyClasses
or even just
SET CLASSPATH=C:\MyJspClasses
The value of the classpath is one or more entries separated by the semi-colon character.   Each element is the path of a directory (folder) or the path of a .jar file.  Whether the element is a directory or a .jar file, it contains class files (with the .class extension.)  These class files get loaded by the Java interpreter and utilities.
You may not have a classpath (specially if you are using JDK 1.3,) in which case you can add one.by adding a line to your autoexec.bat or profile file, or by adding a new environment variable from your Windows NT control panel's "System" panel.
If you already have a classpath, you can insert a new directory into it.
Let us suppose you have modified your classpath and added the path C:\MyJspClasses to it, and have created the C:\MyJspClasses directory.  (On Windows 98, you would also need to re-boot your PC so the class path is in effect.  On NT, you would need to start a new command window so the new class path is picked up.  On Unix, logging in again will activate the changed profile.)
Then you can compile your bean's java file by using the command
    javac -d C:\MyJspClasses UserData.java
which will create the UserData.class file directly into C:\MyJspClasses (and would also have created any necessary directory structure if the class were in a package.)
If you had to change your classpath, typically you will also need to stop and restart your web-server so it can pick up the new classpath.

No comments:

Post a Comment

Main Differences Between SVN and Git