Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

New-to-Java Programming Center

 

New-to-Java Programming Center

New-to-Java Programming Center

Java Platform Overview | Getting Started | Step-by-Step Programming
Learning Paths | References & Resources | Certification

Setting the CLASSPATH Environment Variable
on the Windows Platform

by Dana Nourie

To develop and test applications written in the Java programming language using the Windows environment, set a path and CLASSPATH so programs locate necessary classes and .jar files.

Open the autoexec.bat file (located in the root (\) directory) in a text editor, or type sysedit in Run from the Start button.

To use only the J2SE, include the following in the autoexec.bat file:

PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\JDK\BIN;

This example assumes C:\JDK\BIN is the location that the development kit has been installed on and that the directory name is JDK. The execution files for the tools are kept in bin.

To use additional development tools, additional lines are necessary. The JavaServer Web Development Kit and the MySQL database driver are included as examples of adding tools to the classpath.

SET PATH=%PATH%;%JAVAHOME%\BIN

PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\JDK\BIN;

SET CLASSPATH=.;C:\jdk\lib\tools.jar;
C:\jswdk\lib\servlet.jar;
C:\mm.mysql.jdbc-1.2b;%CLASSPATH%

Note: To ensure programs locate the complier and APIs, keep the SET CLASSPATH command on one line.

Save the file and close the editor. To force these changes, open an MS-DOS window and type autoexec.bat and press Return, or restart your computer.

Test the system with the following steps:

  1. Open a DOS window
  2. Assuming the JDK is installed in a directory called jdk, type:
    cd \jdk\demo\applets\Animator
    
  3. Compile an applet with the following command:
    javac Animator.java
    
  4. Run the applet by typing:
    appletviewer example1.html
    

The animated applet should run on your system. To compile and run other examples, cd to the directory where the applications or applets are saved, then run the javac or appletviewer commands.

Have a question about programming? Use Java Online Support.