< Zurück | Inhalt | Weiter >

6.2.2 Switching Java Versions by Symlink

Here is the process we went through to install both Sun’s Java 2 SDK and IBM’s Java 2 SDK on a system at the same time.

1. Download the Sun JDK as a compressed TAR file.

2. Install it to /usr/java. The Sun installer named its directory

j2sdk1.4.1_02, so the full path is /usr/java/j2sdk1.4.1_02.

3. Download the IBM JDK and untar it also in /usr/java. The base directory in the TAR file was IBMJava2-141, so the path is

/usr/java/IBMJava2-141.

4. Create a symlink called jdk in /usr/java and make it point at the Sun JDK by default (Example 6.3).

5. Add /usr/java/jdk/bin to the system’s default PATH environment variable.4 Also add JAVA_HOME and JDK_HOME environment variables that point to /usr/java/jdk.

Now when we run javac or any other Java command, we run the version which is pointed to by the jdk symlink. If we wish to switch to the IBM JDK, we can just replace the link as show in Example 6.4.

From then on, the machine will be using the IBM Java SDK.

And, of course, by explicitly setting the path and environment variables, you can use whatever you prefer without changing the symlink for all other users on the system. This is an excellent example of how the features of the Linux system can make your life as a Java developer easier—with this general method, you can keep as many Java SDKs from as many vendors as you wish and switch between them at will.

Here, we showed you how to do this on a system-wide basis, but you could, by creating the symlink in your home directory and changing the path for your user account, switch between versions in your own account only, leaving the system-wide default alone. Linux provides endless flexibility for developers.


image

4. Exactly where you do this depends on your distribution. If you aren’t sure, you can always do it in the .bash_profile file in your user account’s home directory.


image

Example 6.3 Symlinking jdk to the Sun Java SDK

# ln -s j2sdk1.4.1_02 jdk

# ls -la total 16

drwxr-xr-x

4

root

root

4096

Jul

8

15:51

.

drwxr-xr-x

17

root

root

4096

Jun

17

10:18

..

drwxr-xr-x

8

root

root

4096

May

21

21:09

IBMJava2-141

drwxr-xr-x

8

root

root

4096

Mar

5

14:44

j2sdk1.4.1_02

lrwxrwxrwx

1

root

root

14

Jul

7

22:33

jdk -> j2sdk1.4.1_02

#










image

Example 6.4 Symlinking jdk to the IBM Java SDK

# rm jdk

# ln -s IBMJava2-141 jdk

# ls -la

total 16


drwxr-xr-x

4

root

root

4096

Jul

8

15:51

.

drwxr-xr-x

17

root

root

4096

Jun

17

10:18

..

drwxr-xr-x

8

root

root

4096

May

21

21:09

IBMJava2-141

drwxr-xr-x

8

root

root

4096

Mar

5

14:44

j2sdk1.4.1_02

lrwxrwxrwx

1

root

root

14

Jul

7

22:33

jdk -> IBMJava2-141

#










6.3 HOW THE IBM JDK DIFFERS FROM THE SUN JDK


After the last chapter, which was one of the longest in the book, this chapter should come as something of a relief. It is one of the shortest in the book. Why? Because the IBM Java Software Development Kit is practically identical in use to the Sun package. It differs in only a few respects and that is all we will talk about here.

One of the biggest differences is the version of Java available from each vendor. Sun has the newest versions, as they have been defining what those are. IBM is still releasing the 1.3 versions of Java as Sun begins to release 5.0. But you may not want or need the “bleeding edge” of the technology.

image

6.3 How the IBM JDK Differs from the Sun JDK 175