Java:系统找不到文件 C:\ ... java.exe

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33355440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:36:11  来源:igfitidea点击:

Java: System cannot find the file C:\ ... java.exe

javapathjavacjava-home

提问by rni902

I have installed Java 8 and set my JAVA_HOMEand JRE_HOMEpaths and added %JAVA_HOME%to the start of the pathvariable.

我已经安装了 Java 8 并设置了我的JAVA_HOMEJRE_HOME路径并添加%JAVA_HOME%path变量的开头。

I created a helloworld.java application and am able to compile it using:

我创建了一个 helloworld.java 应用程序并且能够使用以下方法编译它:

javac helloworld.java

However, when I try to run:

但是,当我尝试运行时:

java helloworld

你好世界

I get the error:

我收到错误:

The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe

How can I solve this?

我该如何解决这个问题?

采纳答案by hab

Just set %JAVA_HOME%/binto your path variable.

只需将 %JAVA_HOME% /bin 设置为您的路径变量。

回答by rni902

I was able to solve this issue. To do so I used the advice from this answer:

我能够解决这个问题。为此,我使用了这个答案中的建议:

Java SE Development Kit 8u25 on a 64-bit Windows 8

64 位 Windows 8 上的 Java SE 开发工具包 8u25

Set the following user environment variables (== environment variables of type user variables)

设置以下用户环境变量(==用户变量类型的环境变量)

?JAVA_HOME : C:\Program Files\Java\jdk1.8.0_25
?JDK_HOME  : %JAVA_HOME%
?JRE_HOME  : %JAVA_HOME%\jre
?CLASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
?PATH      : your-unique-entries;%JAVA_HOME%\bin 

(make sure that the longish your-unique-entries does not contain any other references to another Java installation folder.)

(确保较长的 your-unique-entries 不包含对另一个 Java 安装文件夹的任何其他引用。)

回答by Atul Pundir

1.Just go to C:\ProgramData\Oracle\Java\javapath\

1.只需转到 C:\ProgramData\Oracle\Java\javapath\

2.You will find there shortcuts for java.exe,javaw.exe,javaws.exe which are pointing to a location where they actually are not existing now

2.你会发现有java.exe、javaw.exe、javaws.exe的快捷方式,它们指向一个现在实际上不存在的位置

3.Go to the jre location where you have installed java like C:\Program Files\Java\jre6\bin

3.转到安装java的jre位置,如C:\Program Files\Java\jre6\bin

  1. You will find java.exe,javaw.exe,javaws.exe

  2. Create shortcuts for these files and replace with the ones which are present in C:\ProgramData\Oracle\Java\javapath.

  1. 你会发现 java.exe,javaw.exe,javaws.exe

  2. 为这些文件创建快捷方式并替换为 C:\ProgramData\Oracle\Java\javapath 中存在的快捷方式。

It works

有用

回答by Janac Meena

If you are blocked from modifying system variables from command line, but are able to open up an elevatedcommand prompt, then run a command like this:

如果您无法从命令行修改系统变量,但可以打开提升的命令提示符,请运行如下命令:

setx \M JAVA_HOME "C:\Program Files\Java\jdk1.8.0_25"

setx \M JAVA_HOME "C:\Program Files\Java\jdk1.8.0_25"

But of course, change the directory to point to your installed version of java. Note that the JAVA_HOME path does not point into the bin directory, it stops one level above bin.

但是当然,将目录更改为指向您安装的 java 版本。请注意,JAVA_HOME 路径并未指向 bin 目录,它在 bin 上一级停止。