How to select which JDK to run programatically

176 views Asked by At

I was googling for "Loading" function for Java Swing and ended up in this tutorial.I downloaded the .jnlp file and try to run it. I got an error saying "Your security settings have blocked an application from running with an out-of-date or expired version of Java."

Then something strike in mind asking how do we solve this without changing the setting.

So, my question is, can we predefine which jdk to use in the code. For an example, I have jdk 6, jdk 7 and jdk 8 in my machine, can I set in my code which jdk to use. Let say I want to use jdk 6 to use how do I set in my code and can be support in other platform as well. Any advice or reference link to understand more is highly appreciated.

2

There are 2 answers

0
Aidin On

You can check the java version in your code and stop execution if it is not what you want or check for other available JREs and run another jvm process on executable you want.

Or you can write a script or another program that runs before your code to do this and then run the jvm proccess.

1
PeaceIsPearl On

Try setting JAVA_HOME variable in your environmental variables. Point it to to your C:\Program Files\Java\jdk\jre Also, in Java Control Panel you can choose your jre in the Java Runtime Environment settings