Redhat – Multiple java versions

classpathjavaredhat

I have a server running rhel5 and jre 1.6. All my apps are running perfectly for now. But I want to install java 1.7 but keeping java 1.6 as the default so my running apps want be affected. If I want to install java 1.7 from a rpm how can I do this, and how can I run a my new app with the new version of java without changing default java version

Best Answer

Install the java versions you want, running applications should not be affected despite the default java version being changed. Then run the alternatives utility to pick your default java version:

alternatives --config java
alternatives --config javac

Verify your setup with

java -version
javac -version

If you're unsure, try this on a non-production host first.

Edit: To force tomcat to use a specific java version, no matter what the default, place a setenv.sh in tomcat's bin directory containing

JAVA_HOME=/path/to/jdk

Source: https://stackoverflow.com/questions/1698913/how-to-set-java-home-in-tomcat-config