There are times when you may want to maintain different Java virtual machines on a single Linux box. For example, you may want to test against a certain version without having to touch an already working version.
There are a few techniques for doing this. Sun will install all the Java virtuals machine in to the /usr/java/ directory, with the directory for the specific JVM labelled as the version number. For example /usr/java/jdk1.5.0_08/.
You could create a symbolic link to this directory and have /usr/java/current/ always point to the JVM you want to use.
% cd /usr/java/
% ln -s jdk1.5.0_08 current
% /usr/java/current/bin/java -version
In all your scripts you can then refer to /usr/java/current/ and update the symbolic link accordingly.
Another method is to use the well known JAVA_HOME variable. You can create a small file in /etc/profile.d/ called say java.sh (make it executable chmod a+x /etc/profile.d/java.sh) that will automatically set this everytime you open up a new shell.#!/bin/sh
export JAVA_HOME=/usr/java/jdk1.5.0_08
You can then use the $JAVA_HOME variable in your start up scripts. Nothing is stopping you from utilising a combination of the both techniques at once. Create the JAVA_HOME variable to /usr/java/current/ and then all you do to change between different JVMs is update the symbolic reference.
Whatever technique you use, you should try to resist the urge to hardcode the path to the JVM in any of your start up scripts.