0

On newly installed windows 10 64bit, I did install first, Oracle JDK 12, then installed Oracle JDK 8 update 211, and finally installed Oracle JDK 11.

So now in the C:\Program Files\Java\ there exits 4 folders

jdk1.8.0_211, jdk-11.0.3, jdk-12.0.1, jre1.8.0_211

In the Environment Varibales -> System Varibales I have the JAVA_HOME with value C:\Program Files\Java\jdk-11.0.3 and in the path I have added %JAVA_HOME%\bin

But yet after logout/login and restart still the command java -version on cmd and git bash outputs wrong version

$ java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

How should I fix the problem?

Amir-Mousavi
  • 560
  • 6
  • 11
  • What are the full contents of your `PATH` variable? Is the `%JAVA_HOME%\bin` before all other Java paths? – Mokubai Jun 27 '19 at 17:28
  • What problem? `java -version` is showing the correct information (of course it isn't what you expect it to be). Please provide the contents of your PATH variable. I suspect if you use `java -2 -version` you will get different results. I suspect you will find that the JRE 8 is the cause of your problems. It is unclear the reason you have multiple versions installed. Java 12 has the capability to run Java 11 and Java 8 applications. You can even compile an application to a specific JDK version (depending on the IDE). – Ramhound Jun 27 '19 at 17:28
  • Oppps, There was a `C:\Program Files (x86)\Common Files\Oracle\Java\javapath` in the Path – Amir-Mousavi Jun 27 '19 at 17:32
  • @Ramhound :)) seriously `what problem?` I have written several paragraphs to describe the problem. Having several Java versions is essential for my work. the problem is that I am not a Windows user – Amir-Mousavi Jun 27 '19 at 17:42
  • @Amir-Mousavi - You indicated it was giving you the wrong version, except it, wasn't, it was giving you the correct version due to the contents of your PATH variable. I am very familiar with the need for multiple versions of Java. I was just pointing out the fact, multiple versions of the JDK, are not technically required. – Ramhound Jun 27 '19 at 17:50

1 Answers1

2

Thanks to this answer the commands for %I in (java.exe) do @echo %~$PATH:I showed that there exists a wrong path to java.exe in the Path variable. As the contents of the Path was too long I was not seeing it. in my case (C:\Program Files (x86)\Common Files\Oracle\Java\javapath)

So the solution is:

  • Move that to the end of the list or delete it
  • rename all java*.exe files to e.g. java*_foo.exe in case of future use
Amir-Mousavi
  • 560
  • 6
  • 11