简体   繁体   中英

How Does Java Set It's Path and How Do I Change It?

So I installed the Java 14 JDK (Oracle) and then the Java 8 JRE (Oracle) and before I installed the Java 8 JRE I set the JAVA_HOME system variable to " C:\Program Files\Java\jdk-14.0.1 and added %JAVA_HOME%\bin to PATH and it worked perfectly, the Java 14 JDK was being used for the command prompt and after I installed the Java 8 JRE now Java 8 is being used for command prompt and when I went to check all the information literally nothing was changed so why isn't Java 14 being used for command prompt and how do I fix it?

How does this work?

There is a java.exe in C:\Windows\System32 or something similar that is commonly on the path that points at your 'current' installation, which is controlled by a registry key (HKLM/Software/JavaSoft/ or something similar). Installing the JRE8 second overwrote the 'current version' choice in that registry key, which is causing the java.exe in the system path to go for that one, and not the java.exe from JDK14.

Do you need a JRE / JREs are obsolete.

The real problem is installing a JRE8. Why did you do that? You probably do not need it. You don't need a JRE to run java stuff if you have a JDK (a JDK has all things that a JRE has), JREs as a concept is dead (starting with java9, there are no JREs anymore; the model has changed; instead of end users downloading JREs from oracle and your app from you, the new model is that end users download the JRE and the app, all from you, using for example jlink to create a custom (smaller) JRE just for your app, and thus end users no longer have this 2-step thing which is confusing, and you get to control which version of the 'JRE' is installed, as you installed it).

How do I fix it?

There might be a control panel widget to change the way the win\sys32 java.exe works. Otherwise, go hunt for that JavaSoft key in the registry, find the subkey in there called 'Current Version', and change it to the same key as what describes the j14 install (probably that key is called '14').

That, or, just uninstall JRE8. You don't need it, it's basically unsupported software at this point; leaving it installed is not great for your system's security.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM