Path Help

This section includes instructions on setting the PATH and CLASSPATH environment variables on Win32 and UNIX platforms. Consult the installation instructions included with your installation of the Java 2 SDK software bundle for current information.

After installing both the Java 2 SDK software and documentation, the SDK directory will have the structure shown below. The docs directory is created when you install the SDK documentation bundle.

Figure 125. The file structure of the Java 2 SDK software bundle. Note that the bin directory contains both the compiler and the interpreter.

graphics/apefig01.gif

Update the PATH Variable (Win32)

You can run the Java 2 SDK software just fine without setting the PATH variable. Or, you can optionally set it as a convenience.

Set the PATH variable if you want to be able to conveniently run the SDK executables (javac.exe, java.exe, javadoc.exe, and so on) from any directory without having to type the full path of the command. If you don't set the PATH variable, you need to specify the full path to the executable every time you run it, such as:

C: jdk1.3injavac MyClass.java 

Note

It's useful to set the PATH permanently so it will persist after rebooting. To set it permanently, add the full path of the jdk1.3in directory to the PATH variable. Typically, this full path looks something like C:jdk1.3in. Set the PATH as follows, according to whether you are on Windows NT/2000 or Windows 95/98.

 

Setting the PATH Permanently (Windows NT/2000)

From the Start menu, select the Control Panel > System > Environment, and look for "Path" in the User Variables and System Variables. If you're not sure where to add the path, add it to the right end of the "Path" in the User Variables. A typical value for PATH is:

C:jdk1.3in 

Capitalization doesn't matter. Click Set, OK, or Apply.

The PATH can be a series of directories separated by semicolons (;). Microsoft Windows looks for programs in the PATH directories in order, from left to right. You should have only one bin directory for the Java 2 SDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to 1.3.

The new path takes effect in each new Command Prompt window you open after setting the PATH variable.

Setting the PATH Permanently (Windows 95/98)

To set the PATH permanently, open the AUTOEXEC.BAT file and add or change the PATH statement as follows: Start the system editor. From the Start menu, select Run and enter sysedit in the textbox; then click OK. The system editor starts up with several windows showing. Go to the window that displays AUTOEXEC.BAT.

Look for the PATH statement. (If you don't have one, add one.) If you're not sure where to add the path, add it to the right end of the PATH. For example, in the following PATH statement, we have added the bin directory at the right end:

PATH C:WINDOWS;C:WINDOWSCOMMAND;C:JDK1.3BIN 

Capitalization doesn't matter. The PATH can be a series of directories separated by semicolons (;). Microsoft Windows searches for programs in the PATH directories in order, from left to right. You should have only one bin directory for the Java 2 SDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to 1.3.

To make the path take effect in the current Command Prompt window, execute the following:

C: >c:autoexec.bat 

To find out the current value of your PATH, to see whether it took effect, at the command prompt, type:

C: >C:path 

Check the CLASSPATH Variable

The CLASSPATH variable is one way to tell applications written in the Java programming language (including the SDK tools) where to look for user classes. (The -classpath command line switch is the preferred way.) If your machine does not have the CLASSPATH variable set, you can ignore the rest of this step. To check this, run the set command from the DOS prompt:

C:> set 

If CLASSPATH does not appear in the list of settings, it is not set.

If your CLASSPATH variable is set to a value, you may want to clean up your CLASSPATH settings. The Java 2 SDK works fine even if CLASSPATH is set for an earlier version of the SDK software, as long as it contains the current directory ".". However, if your CLASSPATH contains classes.zip (which was only in JDK 1.0.x and JDK 1.1.x) and you don't plan to continue using those earlier versions, you can remove that setting from the CLASSPATH. In any case, if CLASSPATH is set, it should include the current directorythis makes it possible to compile and to run classes in the current directory.

Update the PATH Variable (UNIX)

You can run the Java 2 SDK just fine without setting the PATH variable, or you can optionally set it as a convenience. However, you should set the path variable if you want to be able to run the executables (javac, java, javadoc, and so on) from any directory without having to type the full path of the command. If you don't set the PATH variable, you need to specify the full path to the executable every time you run it, such as:

% /usr/local/jdk1.3/bin/javac MyClass.java 

To find out if the path is currently set, execute:

% which java 

This will print the path to the java tool, if it can find it. If the PATH is not set properly, you will get the error:

% java: Command not found 

To set the path permanently, set the path in your startup file.

For C shell (csh), edit the startup file (~/.cshrc):

set path=(/usr/local/jdk1.3/bin $path) 

For ksh, bash or sh, edit the profile file (~/.profile):

PATH=/usr/local/jdk1.3/bin:$PATH 

Then load the startup file and verify that the path is set by repeating the which command:

For C shell (csh):

% source ~/.cshrc 
% which java 

For ksh, bash, or sh:

$ . $HOME/.profile 
$ which java 

Checking the CLASSPATH variable

The CLASSPATH variable is one way to tell applications, including the SDK tools, where to look for user classes. (The -classpath command line switch is the preferred way.) If you never set up the CLASSPATH variable for an earlier version of the SDK, you can ignore this step. Otherwise, you may want to clean up your CLASSPATH settings.

The Java 2 SDK will work fine even if CLASSPATH is set for an earlier version of the SDK. However, if your CLASSPATH contains classes.zip for an earlier version, and you don't plan to continue using that version, you can remove that setting from the CLASSPATH now. If CLASSPATH is set but doesn't include the current directory, you should add the current directory to the CLASSPATH value.

To modify the CLASSPATH, use the same procedure you used for the PATH variable in the previous step and do one of the following.

  • Remove classes.zip from the CLASSPATH. Leave any application-specific settings and the current directory, "." If CLASSPATH is set but doesn't include the current directory, you should add the current directory to the CLASSPATH value.)
  • Remove the CLASSPATH environment variable entirely. (With the Java 2 SDK, the default value is "." [the current directory]. For specific applications, you can use the -classpath command line switch.)

Getting Started

Object-Oriented Programming Concepts

Language Basics

Object Basics and Simple Data Objects

Classes and Inheritance

Interfaces and Packages

Handling Errors Using Exceptions

Threads: Doing Two or More Tasks at Once

I/O: Reading and Writing

User Interfaces That Swing

Appendix A. Common Problems and Their Solutions

Appendix B. Internet-Ready Applets

Appendix C. Collections

Appendix D. Deprecated Thread Methods

Appendix E. Reference



The Java Tutorial(c) A Short Course on the Basics
The Java Tutorial: A Short Course on the Basics, 4th Edition
ISBN: 0321334205
EAN: 2147483647
Year: 2002
Pages: 125

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net