Java Reference
In-Depth Information
6.2.2
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.
Switching Java Versions by Symlink
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.
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.
Search WWH ::




Custom Search