23

I have done the following:

1. Set the environment variable JAVA_HOME: enter image description here

2. Add Java 1.6.0_45 and disable Java 1.8.0_66 in Java Runtime Environment Settings under Configure Java: enter image description here

Unfortunately, the Java is still 1.8.0_66:

>java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

Could anyone offer a tip on this?

Edit:

Per David's suggestion, the following is the Java related contents from the output of command PATH (the entire output is super long, I hope the following is sufficient for this question.):

PATH=C:\ProgramData\Oracle\Java\javapath; ... C:\Program Files\Java\jdk1.6.0_45\bin
12
  • 1
    Please edit and include the output of path in a cmd shell.
    – DavidPostill
    Mar 26, 2016 at 11:23
  • @DavidPostill I have just done it following your suggestion. Thank you.
    – Hong
    Mar 26, 2016 at 11:37
  • 1
    C:\ProgramData\Oracle\Java\javapath will be 1.8.0_66. Put C:\Program Files\Java\jdk1.6.0_45\bin first.
    – DavidPostill
    Mar 26, 2016 at 11:39
  • Note that changes to environment variables may not be fully applied until you sign in again. Reboot and try java -version again.
    – gronostaj
    Mar 26, 2016 at 11:41
  • 2
    Have you tried to put just ´%JAVA_HOME%\bin´ instead ´C:\Program Files\Java\jdk1.6.0_45\bin´ Mar 26, 2016 at 11:45

7 Answers 7

20

java -version is running the wrong version of java.

Diagnostics:

>java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

the following is the Java related contents from the output of PATH:

PATH=C:\ProgramData\Oracle\Java\javapath; ... C:\Program Files\Java\jdk1.6.0_45\bin

Conclusion:

From the above output we can deduce that C:\ProgramData\Oracle\Java\javapath is 1.8.0_66.

You need to change your PATH to put C:\Program Files\Java\jdk1.6.0_45\bin first.

I noticed that after checking the path per your suggestion. Windows 10 does not allow me to edit the path because it says "This environment variable is too large." I know there should be another question to deal with this separately.

You also need to clean up your path. My guess is you have a lot of duplicate entries.

2
  • 2
    Order changing doesn't help, java -version is always 8. My configuration: Windows 10 with jdk 8 installed alongside jdk 7. Mar 12, 2018 at 14:13
  • @naXa Please ask your own question, supplying the appropriate information.
    – DavidPostill
    Mar 12, 2018 at 14:15
16

I have the same problem, I have set JAVA_HOME:

C:\Program Files\Java\jdk1.7.0_75

and Path to:

%JAVA_HOME%\bin

I need run jdk 7. When I run java -version it always appear jdk 8.

I solved it with: in System Environment --> Path --> order %JAVA_HOME%\bin to first.

4
  • This answer is correct Apr 25, 2018 at 15:09
  • This is the correct answer !! Thank you very much !!
    – Shalika
    Jun 30, 2019 at 8:58
  • 1
    I had to restart my computer before it worked.
    – ponder275
    Jun 15, 2020 at 14:37
  • After hours of experimenting with the environment variables and the java config settings in VS Code, this finally made it clear what actually determined which version of java was running... thank you
    – asa9ohan
    Nov 22, 2020 at 18:52
5

This is the REAL active JAVA executable into your PATH:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath;

Remove it and the system take the value from

...;%JAVA_HOME%\bin\;
1
  • 4
    No, it's not a "REAL" java! It's the oracle's way to redirect the "java.exe", etc. simple executions to the "REAL" java installation, which is specified in Computer\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment So this solution is replacing the registry-based indirection (managed by java installers) with the Environment-variable based indirection (managed by theuser). See also: stackoverflow.com/a/51457823/849897
    – MGM
    Apr 15, 2019 at 14:02
2

enter image description here

As you can check the javapath variable under system's environment path variable.

So if you want to use your own version.You can do

  • 1) Create new variable in systems variable
  • 2) Name it as JAVA_HOME and give jdk installation path
  • 3) add this variable in path and move it to top.
  • 4) check java -version

you need to create a JAVA_HOME

2

Check also registry. Press Win key-R, type regedit. Search for Computer\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment. If there is something different, than you expect, than it is better to reinstall Java. If it not possible, very carefully change the settings. Be aware, that from version to version the setup can be different. In my case I would to downgrade from Java 1.9 to 1.8.

Java Registry Setup

1

I just uninstalled Java6 that resides in c:Windows\System32 like a noxious weed. Problem gone.

1
  • With old java installers a java.exe is often present in c:\Windows\System32 the classic headache! Nov 19, 2021 at 11:56
0

After reviewing the other recommendations, I still found Windows 10 to be running the wrong version of Java. The correct version of Java ran in a command shell, but Windows would not start an application with the correct version of Java.

In my system, there was yet another entry in the Registry. So, I opened the registry editor, and changed Computer\HKEY_CLASSES_ROOT\jarfile\shell\open\command to point to the correct version.

This finally fixed the problem I was having.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .