13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.2 Use <strong>Linux</strong> Features to Make Multiple Java SDKs Play Nicely Together1736.2.2 Switching Java Versi<strong>on</strong>s by SymlinkHere is the process we went through to install both Sun’s Java 2 SDK andIBM’s Java 2 SDK <strong>on</strong> 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 directoryj2sdk1.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 basedirectory 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 SunJDK by default (Example 6.3).5. Add /usr/java/jdk/bin to the system’s default PATH envir<strong>on</strong>mentvariable. 4 Also add JAVA_HOME and JDK_HOME envir<strong>on</strong>ment variables thatpoint to /usr/java/jdk.Now when we run javac or any other Java command, we run the versi<strong>on</strong>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 <strong>on</strong>, the machine will be using the IBM Java SDK.And, of course, by explicitly setting the path and envir<strong>on</strong>ment variables,you can use whatever you prefer without changing the symlink for all otherusers <strong>on</strong> the system. This is an excellent example of how the features of the<strong>Linux</strong> system can make your life as a Java developer easier—with this generalmethod, you can keep as many Java SDKs from as many vendors as you wishand switch between them at will.Here, we showed you how to do this <strong>on</strong> a system-wide basis, but youcould, by creating the symlink in your home directory and changing the pathfor your user account, switch between versi<strong>on</strong>s in your own account <strong>on</strong>ly,leaving the system-wide default al<strong>on</strong>e. <strong>Linux</strong> provides endless flexibility fordevelopers.4. Exactly where you do this depends <strong>on</strong> your distributi<strong>on</strong>. If you aren’t sure, you can alwaysdo it in the .bash_profile file in your user account’s home directory.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!