“系统找不到文件 C:ProgramDataOracleJavajavapathjava.exe"

2022-01-15 00:00:00 environment-variables java

我在 Windows 8 上使用 JDK 8u25,我在安装 Java 时遇到问题.我可以很好地运行 javac,但运行 java 会产生以下错误消息:

I am on JDK 8u25 on Windows 8, and I am experiencing a problem with my Java installation. I can run javac perfectly fine, but running java produces this error message:

The system cannot find the file C:ProgramDataOracleJavajavapathjava.exe

我该如何解决这个问题?

How do I fix this?

我认为问题与我的环境变量有关.

I think the problem has to do with my environment variables.

我设置的重要变量是:

  • JAVA_HOMEC:Program FilesJavajdk1.8.0_25
  • CLASSPATH.;%JAVA_HOME%lib
  • PATH<省略其他路径>;%JAVA_HOME%in
  • JAVA_HOMEC:Program FilesJavajdk1.8.0_25
  • CLASSPATH.;%JAVA_HOME%lib
  • PATH<other paths omitted>;%JAVA_HOME%in

它们的扩展,在cmd中用set查看,是:

And their expansions, as viewed with set in cmd, are:

  • JAVA_HOMEC:Program FilesJavajdk1.8.0_25
  • CLASSPATH.;C:Program FilesJavajdk1.8.0_25lib;%CLASSPATH%;
  • PATHC:ProgramDataOracleJavajavapath;C:Program FilesJavajdk1.6.0_45in;<省略其他路径>;C:Program FilesJavajdk1.8.0_25in
  • JAVA_HOMEC:Program FilesJavajdk1.8.0_25
  • CLASSPATH.;C:Program FilesJavajdk1.8.0_25lib;%CLASSPATH%;
  • PATHC:ProgramDataOracleJavajavapath;C:Program FilesJavajdk1.6.0_45in;<other paths omitted>;C:Program FilesJavajdk1.8.0_25in

set 的完整输出可以查看这里.

The full output of set can be viewed here.

推荐答案

我有一个类似的问题,我目前正在努力解决.我不能说这会解决您的错误,因为其他软件可能存在问题(Eclipse Luna 就是这种情况).

I've got a similar problem I'm currently working on solving. I can't say this will solve your error since there may be issues with other software (which is my case with Eclipse Luna).

Java 正在使用 PATH 变量中给出的路径,即,

Java is using the path given in your PATH variable, which is,

  C:ProgramDataOracleJavajavapath

转到此文件夹(ProgramData 已隐藏,因此如有必要请取消隐藏)并右键单击 java.exe 符号链接.您将在 Target 字段中看到它正在寻找 java.exe.它可能指向您之前安装的 jdk1.6.0_45 中的 java.exe 文件.要么在此处粘贴新的快捷方式,要么像其他人提到的那样更改 PATH 设置.

Go to this folder (ProgramData is hidden, so unhide it if necessary) and right click on the java.exe symlink. You'll see in the Target field where it's looking for java.exe. It may be pointing to the java.exe file from your previous jdk1.6.0_45 install. Either paste in new shortcuts here or change the PATH setting as others have mentioned.

我发现 Java 安装程序不会更改 javapath 或更新系统路径,至少在从 1.8 升级到 1.7 时是这样.在我的情况下,更改快捷方式只会导致 Eclipse 在启动时出现问题.

I've found that the Java installer doesn't change the javapath or update the system path, at least when going from 1.8 to 1.7. In my case changing the shortcuts only led to a problem with Eclipse on startup.

--在使用 javapath 文件夹快捷方式后,事实证明您需要符号链接,至少对于 Eclipse 来说是这样.请参阅Windows 如何创建目录符号链接.

----- After playing with javapath folder shortcuts it turns out you need symlinks, at least for Eclipse. See, Windows how to create directory symlink.

文件符号链接不需要/d 开关,

You don't need the /d switch for a file symlink,

  mklink java.exe "C:Program FilesJavajdk1.8.0_20injava.exe"
  mklink javaw.exe "C:Program FilesJavajdk1.8.0_20injavaw.exe"
  mklink javaws.exe "C:Program FilesJavajdk1.8.0_20injavaws.exe"

这对我有用.

相关文章