Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which JRE does C:\ProgramData\Oracle\Java\javapath\java.exe use?

Tags:

java

I'm trying to figure out which environment variable java uses to find/detect the JRE used by C:\ProgramData\Oracle\Java\javapath\java.exe.

As per Oracle's design, the only files I have in the C:\ProgramData\Oracle\Java\javapath\ are

  • java.exe
  • javaw.exe
  • javaws.exe

If I set my JAVA_HOME to empty or to some random folder, running an application with java.exe still works. So I can only assume that it isn't using the JAVA_HOME value. So how does it find the JRE folder? Does it default to something specific? I have no JRE_HOME var set either.

like image 934
Eric B. Avatar asked Mar 28 '18 17:03

Eric B.


People also ask

What is Javapath?

The path is the most important environment variable of the Java environment which is used to locate the JDK packages that are used to convert the java source code into the machine-readable binary format. Tools like javac and java can be used by setting the path.

What is the path to Java EXE?

The java.exe Executables Two copies of the java.exe executable are installed. One copy is in the bin directory of the Java RE. The second copy is placed in either C:\windows\system or C:\winnt\system32 , depending on the system.

Where is Javapath?

c:\ProgramData\Java\javapath is used for symlinks. You can of course add the full path to your Java Path to %PATH% , but equally you can create a symlink to the path to the above location.


3 Answers

As of 2018, and specifically with regards to Oracle Java, you might find your Java runtime installed in one of two ways:

Regular Directory with File Symlinks inside

If you look at the files in C:\ProgramData\Oracle\Java\javapath\ you will see that they are actually symlinks to specific java binaries.

2015-11-13  06:11 PM    <SYMLINK>      java.exe [C:\Program Files\Java\jre1.8.0_65\bin\java.exe]
2015-11-13  06:11 PM    <SYMLINK>      javaw.exe [C:\Program Files\Java\jre1.8.0_65\bin\javaw.exe]
2015-11-13  06:11 PM    <SYMLINK>      javaws.exe [C:\Program Files\Java\jre1.8.0_65\bin\javaws.exe]

Directory Junction with regular Files inside

Using the latest (64! bit) install of Java 8 actually prepends onto the system path another location: c:\Program Files (x86)\Common Files\Oracle\Java\javapath. This time, the javapath itself is the junction:

2018-07-21  05:59 PM    <JUNCTION>     javapath [C:\Program Files (x86)\Common Files\Oracle\Java\javapath_target_172906453]
2018-07-21  05:59 PM    <DIR>          javapath_target_172906453

And now, interestingly, the java.exe etc. in the javapath_target_... folder are not symlinks. These files find JRE and JDK versions using this registry location:

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment]
"CurrentVersion"="1.8"

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.8]
"JavaHome"="C:\\Program Files\\Java\\jre1.8.0_65"
like image 99
Chris Becke Avatar answered Oct 19 '22 02:10

Chris Becke


This will give you an idea:

java -verbose | more
like image 22
access_granted Avatar answered Oct 19 '22 01:10

access_granted


These "new" JDK 8 / 64-bit behavior is so obfuscated, I could not guess why my application would not start, because I had the JDK (with the private JRE) and every path variable setup, still no start. After some time I installed JRE8 alone and it worked. Firstly the regedit - keys are only written by the public JRE.... Ok.

Then I wanted to know which Runtime the app used, I renamed all java* .exe, yet it still worked64-bitI renamed all-new regedit keys. It still worked...

End of story: with Windows 64 the regedit keys are in HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft (32bit) and

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\JavaSoft (64bit)

and my app worked because

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\JavaSoft\Java Runtime Environment\1.8\RuntimeLib\ 

pointed to jvm.dll which referenced a symlink. I need a beer, I want another Job :-)

Here is a nice link, which explains the Regedit-Keys and the different "discovery methods" which Java uses to find the newest installed version:

http://mindprod.com/jgloss/registry.html

Still the SYSLink - Change with JDK8 seems to be an undocumented change which was introduced before JRE8u171.

My sysLink Path was C:\Program Files (x86)\Common Files\Oracle\Java with was actually a Junction to a subdirectory. And the JDK8 installer copies the java*.exe files into Windows\System32\ btw.

More Infos:

  • http://makble.com/jdk-8-and-cprogramdataoraclejavajavapath - What's the sense of C:\ProgramData\Oracle\Java\javapath (on Windows 10)?

  • https://community.oracle.com/thread/4143254 https://douglascayers.com/2015/05/30/how-to-set-custom-java-path-after-installing-jdk-8/

Sorry for my rant, I'm so frustrated right now. I hope it helps somebody else.

like image 14
98percentmonkey Avatar answered Oct 19 '22 03:10

98percentmonkey