Java路径设置错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27080846/
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 03:46:53  来源:igfitidea点击:

Java path set wrongly

javawindowswindows-8

提问by user3387219

I have installed Java on a new system. Some random path in my C drive is automatically set for my PATHvariable. Whenever I try to run Java, it shows java.exe not foundin that wrong path!

我已经在新系统上安装了 Java。我的 C 驱动器中的一些随机路径是为我的PATH变量自动设置的。每当我尝试运行 Java 时,它都会显示java.exe not found在错误的路径中!

I'm trying to change the PATHvariable using the SETcommand, but the new path is only getting added along with the old one. I could not run Java on the system.

我正在尝试PATH使用SET命令更改变量,但新路径只会与旧路径一起添加。我无法在系统上运行 Java。

set PATH=%PATH%;C:\Program Files\Java\jdk1.7.0_71\bin 

I've tried setting PATHvariable in Windows Environment Variables list also after setting JAVA_HOME!

设置后,我也尝试PATH在 Windows 环境变量列表中设置变量JAVA_HOME

When I type Java in cmd, i get:

当我在 中输入 Java 时cmd,我得到:

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

系统找不到文件 C:\ProgramData\Oracle\Java\javapath\java.exe。

This path is the old unknown automatically set path.

这个路径是旧的未知自动设置的路径。

Is there any way to run Java! I'm using windows 8.

有没有办法运行Java!我正在使用 Windows 8。

采纳答案by prsutar

if you are using windows system, please create java_home as a variable and set java home path i.e. till C:\Program Files\Java\jdk1.7.0_71, and in path variable do not delete existing just append new with ;%java_home%\bin

如果您使用的是 windows 系统,请创建 java_home 作为变量并设置 java home 路径即直到C:\Program Files\Java\jdk1.7.0_71,并且在路径变量中不要删除现有的只是附加新的;%java_home%\bin

this will work

这会起作用

in you case SET is valid till command prompt is open. do the above changes in my computer -> properties -> advanced ->environment variables

在你的情况下 SET 有效,直到命令提示符打开。在我的电脑中做上述更改 -> 属性 -> 高级 -> 环境变量

回答by Yusuf Kapasi

set PATH=C:\Program Files\Java\jdk1.7.0_71\bin; 

will set the path of java only and the old path will not get added and that will be till the command prompt session lasts.

将仅设置 java 的路径,不会添加旧路径,直到命令提示符会话持续。

to keep the existing path setting intact and add the java path use below command.

保持现有路径设置不变,并在下面的命令中添加 java 路径使用。

set PATH=C:\Program Files\Java\jdk1.7.0_71\bin;%PATH%

回答by user2767222

I know this post id very old. I faced this issue recently. Please follow the following steps to resolve your issue:

我知道这个帖子很老了。我最近遇到了这个问题。请按照以下步骤解决您的问题:

  1. Search for "Regedit" in "start menu".
  2. Once found, right-click it and choose "run as Administrator" option.
  3. Enter your administrator credentials and Enter.
  4. Go to "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.7"
  5. Double-click on "JavaHome" name and change its value to "C:\Program Files\Java\jdk1.7.0_71".
  6. Close all your command prompts and open a new Command prompt and it should reflect.
  1. 在“开始菜单”中搜索“Regedit”。
  2. 找到后,右键单击它并选择“以管理员身份运行”选项。
  3. 输入您的管理员凭据并回车。
  4. 转到“HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java 运行时环境\1.7”
  5. 双击“JavaHome”名称并将其值更改为“C:\Program Files\Java\jdk1.7.0_71”。
  6. 关闭所有命令提示符并打开一个新的命令提示符,它应该会反映出来。