On Windows, why java -version return Error: opening registry key 'Software\JavaSoft\Java Runtime Environment'?

72,576

Solution 1

How to make it work:

Windows > Start > cmd >

C:> for %i in (javac.exe) do @echo.   %~$PATH:i

or

C:> where java

It returns C:\ProgramData\Oracle\Java\javapath folder which contain:

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

Browse to this folder with Windows file explorer and remove everything (three files above).

Close and reopen cmd (Windows > Start > cmd >)

C:> java -version

Should now return:

openjdk version "11.0.1" 2018-10-16

OpenJDK Runtime Environment 18.9 (build 11.0.1+13)

OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

or something similar depending on which java release package you've downloaded...

It works!

Solution 2

I came across same issue,

how to check:

  1. open cmd, execute "where java" (without quote)
  2. you should see more than one output of the java path, one of it should be the one you set "C:\Program Files\Java\jdk-11.0.1\bin", the other ones should be in above

how to solve:

option 1:

simply delete all the other java path

option 2:

check your enviroment variable setting, move your %JAVA_HOME%\bin to the above all the other java path

Share:
72,576
O. Durand
Author by

O. Durand

Updated on September 18, 2022

Comments

  • O. Durand
    O. Durand over 1 year
    1. I've removed all ancient Java 8 install on my computer.
    2. I've downloaded latest openjdk 11 from https://jdk.java.net/11/ and extracted the content to C:\Program Files\Java\.
    3. I've setup system environment variable to

      JAVA_HOME = C:\Program Files\Java\jdk-11.0.1
      

      and added %JAVA_HOME%\bin to Path.

    4. In a command prompt > java -version returns:

      Error: opening registry key 'Software\JavaSoft\Java Runtime Environment'
      Error: could not find java.dll
      Error: Could not find Java SE Runtime Environment.
      
    5. Why?

  • Bill Menees
    Bill Menees almost 5 years
    Thanks! The above steps fixed the error I was getting. Then to finish the clean-up, I deleted the C:\ProgramData\Oracle folder since it didn't contain anything else useful to me. I also removed C:\ProgramData\Oracle\Java\javapath from my system PATH environment variable where Oracle had left it as the first entry.
  • Sven M.
    Sven M. over 4 years
    Thank you so much! I was getting really frustrated.
  • Fatmajk
    Fatmajk about 4 years
    Thanks! It works.
  • android developer
    android developer about 4 years
    How do I "simply delete all the other java path" ? Or "move your %JAVA_HOME%\bin to the above all the other java path" ?
  • LIU YUE
    LIU YUE about 4 years
    for Windows by “edit system environment”
  • android developer
    android developer about 4 years
    Seems to work fine now. Thanks.
  • rickz
    rickz over 3 years
    Thank you! This worked for me