问题描述

进入CMD,执行java相关命令,提示如下错误:


C:\Users\teclan>java -version
Error: opening registry key 'Software\JavaSoft\Java Runtime Environment'
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

C:\Users\teclan>echo %JAVA_HOME%
C:\Program Files (x86)\Java\jdk1.6.0_39

C:\Users\teclan>java
Error: opening registry key 'Software\JavaSoft\Java Runtime Environment'
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

方案

这明显是java的环境变量出现了问题,经过网上查找资料,基本上是以下几个方案:

  1. 删除 C:\windows\system32下的 java.exe (实测win64在此目录并没有这个文件,而是在C:\Windows\SysWOW64,删除java.exe后重启并没有解决)

  2. 修改注册表,例如在stackoverflow提供的方案

1. In the START menu type "regedit" to open the Registry (be careful doing this)
2 .Go to "HKEY_LOCAL_MACHINE" on the left-hand side registry explorer/tree menu
3. Click "SOFTWARE" within the "HKEY_LOCAL_MACHINE" registries
4. Click "JavaSoft" within the "SOFTWARE" registries
5. Click "Java Runtime Environment" within the "JavaSoft" list of registries
6. Highlight "CurrentVersion" (should see it in the main registry key explorer window on the right)
6. Change version to "1.7"

实测,在JavaSoft节点下,就没有Java Runtime Environment这个节点,系统是win7-64

回到问题本质,既然应该是环境问题,检查JAVA_HOME,没有问题,接着检查classpath,也是OK,转到Path,发现有一个值是 C:\ProgramData\Oracle\Java\javapath;,明显是跟java有关,但是这个并不是自己配,而且一看就是跟Oracle有关,实际上 机器上装了一个sqldevelper,应该是这个货自己的环境变量。将这个环境变量备份,从path中移出这个环境变量,再次在CMD中执行 java命令,环境就变正常了,并且sqldeveloper也能正常使用。


C:\Users\teclan>java -version
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode, sharing)

C:\Users\teclan>java
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -client       to select the "client" VM
    -server       to select the "server" VM
    -hotspot      is a synonym for the "client" VM  [deprecated]
                  The default VM is client.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
...

至此,问题处理结束。