If my machine have multiple version of jre installed say jre 5, jre 6 and jre 7. Is it possible to force my application to use specific jre (say jre 5) at runtime?
Launch the app. using Java Web Start. It provides many options for Runtime Versioning.

All the ticked JREs are available for use by JWS launched apps.
Here is how you might select any 1.5 variant in the launch file.
<j2se version="1.5" />
I have on my computer 3 JDKs. Every JDK has own environment variable
%JAVA_HOME_1_5%
%JAVA_HOME_1_6%
%JAVA_HOME_1_7%
when I want use specific JDK, I set %JAVA_HOME% to this variable.
Also I use scripts for using different JDK. For example, if I want start Jboss using JDK 6, I run next script
set JAVA_HOME=%JAVA_HOME_1_6%;
%JBOSS_HOME%/run.bat
If I want execute runnable jar (using JDK 5) I run next script
%JAVA_HOME_1_5%/bin java MyJar.jar
If I want run maven with JDK 7, I am using next script
set JAVA_HOME=%JAVA_HOME_1_7%
mvn clean install -Dmaven.test.skip=true
etc.
So you can use any JDK using env. variables and simple scripts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With