Setting the Path

     

Setting the Path

Setting the Path variable allows you to run the Java SDK executable programs, such as java and javac, from any directory on your system. It is a very good idea to set this variable, for convenience. If you do not set the Path variable, you need to specify the location of the javac compiler and java runtime every time you try to compile and run a program. Here's how to set it.

On Windows

In Windows 2000, set the Path like this: click Start > Settings > Control Panel > System > Advanced Tab > Environment Variables . Create a variable called path and set its value to the location of the <J2SDK-install-location>\bin directory. For example, it might be this:

 

 C:\Program Files\Java\J2SDK1.5.0\bin 

The Path can be a series of directories separated by semi-colons (;). Windows looks for programs in the Path directories from left to right.

On Linux

Linux uses a : to separate path variables. You can set the path on Linux by editing your /etc/profile file (su root first) to the location of your Java installation. Your installation may already have a JDK on it (RedHat and many others come with the Java SDK). So just type java at a terminal and see if you get usage information. If you do, you can use it. But this is likely to be a 1.4 JDK for some time.

On Mac OSX

Mac OS version 10.3 comes pre-installed with a Java SDK, which at this writing is version 1.4.1_03. While many of the examples in this book will work with that version, some important syntax has been added, and you probably will want to upgrade. To do so, just go to Finder and getting a terminal window ”then you can follow the Linux instructions since Mac OSX is a mix of BSD distros under the hood.

There should be only one bin directory for a Java SDK in the path at a time. Any directory specified subsequent to the first is ignored. So if there is already a PATH variable set (say, because of an IDE or previous version), you can update it to j2sdk1.5.0\bin.

You can verify that this is working correctly by typing the java command at a prompt like this:

 

 C:\garage>java -version 

It should output version information similar to the following:

 

 java version "1.5.0" Java(TM) 2 Runtime Environment, Standard Edition       (build 1.5.0) Java HotSpot(TM) Client VM (build 1.5.0-32c,       mixed mode) 

You should now be able to compile Java source code and execute Java programs from any directory in your system. Note that if you use an IDE, you might need to make sure that it is pointing to your 1.5 JDK, and not a separate JDK that it ships with, which could be a different version that's incompatible with some examples in this book. For more information on the different tools that come with the SDK, see the SDK tools section at the back of the garage.



Java Garage
Java Garage
ISBN: 0321246233
EAN: 2147483647
Year: 2006
Pages: 228
Authors: Eben Hewitt

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