Owl Teach Yourself Java 2 in 21 Days Professional Reference Edition, Second Edition
HOME / ORDER THE BOOK / OTHER BOOKS / THANKS
ROGERS CADENHEAD

Using the SDK on a Windows System

Editing CLASSPATH

When you compile a Java program with the SDK, you type a command such as the following at a command line:

  • javac HelloWorld.java

If you compile a program successfully, you won't see any output. Try to run the program:

  • java HelloWorld

If programs compile and run OK, the Software Development Kit has been configured successfully. You don't need to make any more changes.

If you see a "class not found" error whenever you try to compile a program, you need to make one more adjustment.

If you're using Windows XP, 2000, or NT, skip to the next section.

Setting Up CLASSPATH on Windows 95, 98, and Me

There's one more line that needs to be edited, or added, to your AUTOXEC.BAT file: The CLASSPATH.

When you run Notepad and open \AUTOEXEC.BAT, you'll see a series of MS-DOS commands like those shown below.

Editing AUTOEXEC.BAT

The SET CLASSPATH= command is followed by a series of folder and filenames separated by semi-colons.

CLASSPATH is used to help the Java compiler find the Java class library and other class files that it needs. In the preceding example, the SET CLASSPATH= command highlighted in green includes three things:

  • .
  • c:\jdk1.3\lib$classfile
  • c:\jdk1.3

A CLASSPATH can contain folders (such as c:\jdk1.3 in the preceding example) and files (c:\jdk1.3\lib$classfile). It also can contain a period character ("."), which is another way to refer to the current folder in MS-DOS.

You can see what CLASSPATH has been set to by typing the following command at an MS-DOS Prompt:

  • ECHO %CLASSPATH%

If your CLASSPATH includes folders or files that you know are no longer on your computer, you should remove the references to them on the SET CLASSPATH= line in AUTOEXEC.BAT. Make sure to remove any extra semi-colons also.

To set up the Java Development Kit correctly, the file containing the Java class library must be included in the SET CLASSPATH= command. The interpreter has the filename tools.jar. If you installed the JDK in the C:\jdk1.3 folder on your system, tools.jar should be in C:\jdk1.3\lib.

If you can't remember where you installed the SDK, you can look for tools.jar by clicking Start, Find, Files or Folders. If you find several copies, you should be able to find the correct one using this method:

  • Use CD to open the folder that contains the Java interpreter (java.exe)
  • Enter the command CD ..
  • Enter the command CD lib

The lib folder should contain the right copy of tools.jar.

When you know the correct location, create a blank line at the bottom of the AUTOEXEC.BAT file and add the following:

  • SET CLASSPATH=%CLASSPATH%;.;rightlocation

For example, if tools.jar file is in the c:\javajdk\lib folder, the following line should be added at the bottom of AUTOEXEC.BAT:

  • SET CLASSPATH=%CLASSPATH%;.;c:\javajdk\lib$classfile

As you might expect, the %CLASSPATH% text keeps you from removing any other CLASSPATH commands in AUTOEXEC.BAT.

After making changes to AUTOEXEC.BAT, save the file and reboot your computer. Once this is done, try to compile one of the sample programs from this Web site.

If you are still having problems running java -version or getting "class not found" errors after completing this tutorial, send e-mail to my SDK setup mailbox.

Setting Up ClassPath on Windows NT, 2000, or XP

On a Windows 2000, NT, or XP system, there's one more environment variable that may need to be edited, or added, in your Control Panel: The ClassPath variable.

To see the variables set up on your computer:

HOME / ORDER THE BOOK / OTHER BOOKS / THANKS

Workbench | Books | RSS Feed | RSS Spec | Copyright 2018 World Readable