Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple versions of "JDK", which "java.exe" file to execute?

Tags:

java

I have installed multiple versions of JDK, including 1.6,1.7,1.8.

I want to know which version of java.exe gets executed when I run software that needs JRE. I did some testing, see below:

Tests:

cmd.exe command: echo %java_home%
prints: java version "1.8.0_31"


cmd.exe command: java -version
prints: java version "1.8.0_31"


Then I checked the register table in HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.8 and got the javaHome key value
result: C:\Program Files\Java\jdk1.8.0_31.


java code: System.out.println(System.getProperty("java.home"));
prints: C:\Program Files (x86)\Java\jdk1.7.0_15\jre


Finally, I opened the task manager, searched the java.exe process and located the java.exe directory at:
result: C:\Program Files (x86)\Java\jdk1.7.0_15\bin


Question:

I'm confused which jave.exe file the computer chooses. Can you help?

like image 706
Sung Qee Avatar asked Jan 28 '26 17:01

Sung Qee


1 Answers

Passive approach

You may want what the where windows command line utility does; assuming you have only one java.exe in your %PATH%

Try:

where java.exe

If you have multiple version of java pin your %PATH% this will return multiple values. (unfortunately)

Active approach

Set your environment this way:

Have your PATH environment variable to point ONLY to c:\tools\java\default

Store all your jre in one folder like

C:\tools\Java\JRE_1.6
C:\tools\Java\JRE_1.7
C:\tools\Java\JRE_1.8

Then open a comman propt and inside C:\tools\Java\ execute

junction default JRE_1.6

This will create a junction (wich is more or less like a symbolic lync).

In this way you will always have your default java in c:\tools\java\default. If you then need to change your default java to the 1.8 version you just neet to execute

junction -d default
junction default JRE_1.8   
like image 157
snovelli Avatar answered Jan 31 '26 07:01

snovelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!