Multiple JREs can reside on the same machine. However, if you install JRE6, that's the same as upgrading to Java 6. Java 6 is (as far as I can tell) able to run all older Java code. However, Java 6 binary (.class
and .jar
files) can not be executed using Java 5, unless they were compiled to target the previous version.
If you need to, you can target Java 5 using a Java 6 JDK. There are command line arguments for javac
that you can use (or incorporate into Ant, and probably other build tools) to specify a target JRE. For example, if you used the -target 1.5
command-line option using your JDK, the .class
or .jar
files that are produced will be executable using the Java 5 JRE.
It's been a while since I have ran two JREs side-by-side, but unless things have changed, there will be two separate java.exe (on Windows, anyway) files - one for the previous Java 5 JRE and a new one for the Java 6 JRE. Due to naming, only one can be in the path at a time - all of the files have the same names, so you can't include the Java 5 and Java 6 java.exe at the same time and expect the right one to magically run. However, you can leave the Java 5 JRE in your path and manually invoke the Java 6 java.exe when you execute your application.
If you use JAVA_HOME
set to the Java 5 JRE and set a new environment variable to the Java 6 Java Home, let's say JAVA_1.6
, as long as you properly reference the right environment variable, you should be fine.