Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch between multiple java versions JDK1.8 and JDK10

Once I install jdk 8 and jdk 10, jdk version 10 is getting configured as system JDK. Even though I change JAVA_HOME, PATH to jdk 8, system jdk does not changes. After changing path and JAVA_HOME if I check version of java in command prompt, it shows jdk 8. But if I double click an executable jar file it takes system jdk i.e. jdk 10.

I tried changing registry to edit the system jdk paths and versions but it didn't work.

From configure java I can only see jdk 10 as configured as system jdk and non editable.

Please help if you are able to switch jdk versions as system jdk.

Steps to replicate issue:

  1. install jdk 8
  2. install jdk 10
  3. without uninstalling jdk 10 change java home and path to jdk 8 from command prompt check java version, it will show jdk 8
    1. Now try to run an executable jar by double click on desktop. It will take jdk 10. That is the issue.

NOTE: This is not a duplicate post. There are posts on switching between jdk6 or 7 or 8 but not with jdk 10. JDK 10 also does not comes with zip distribution from oracle, it comes only as installable file.

like image 701
DS_ Avatar asked Oct 23 '25 12:10

DS_


2 Answers

Usually, your PATH already contains a reference to %JAVA_HOME%\bin (e.g. on Windows), so adding / appending it again to the path will have no effect. You can either fix the PATH by removing the existing reference, or prepend the new setting.

On windows:

C:\>set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_1.41
C:\>set PATH=%JAVA_HOME%\bin;%PATH%

Now, the previous reference is still on the path, but after the new reference, thus it will be ignored.

like image 84
Lukas Eder Avatar answered Oct 25 '25 01:10

Lukas Eder


There isn't officially any such thing as a "system jdk". When you double-click on a file, it's the file association that determines what program is used to open that file. How a file association is defined depends on your operating system. For example, on Windows, there are two places where file associations are stored. The first is in the Registry under HKLM\Classes, which is used by the command line, but this can be overridden by a Windows Explorer-specific association. It's probably not worth the hassle of changing file associations for .jar files every time you switch JDKs. Instead, just go to the command line and type java -jar myapp.jar. Then it will take whatever java version you've defined on the PATH.

like image 25
DodgyCodeException Avatar answered Oct 25 '25 01:10

DodgyCodeException