java JAVA_HOME 设置但不生效

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

JAVA_HOME set but not taking effect

java

提问by Jabir

enter image description here

在此处输入图片说明

As depicted in above image java home is set and is being echoed but when i check for version it gives me latest version. Already restarted the command prompt after setting env variable. OS is Windows 7

如上图所示,java home 已设置并正在回显,但是当我检查版本时,它给了我最新版本。设置 env 变量后已经重新启动了命令提示符。操作系统是 Windows 7

Update:

更新:

Following is the Path.

以下是路径。

..ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;;%JAVA_HOME%/bin;

..ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;;%JAVA_HOME%/bin;

回答by nazar_art

I had the same trouble and I solved it with following steps:

我遇到了同样的问题,我通过以下步骤解决了它:

You need correct environment variables.

你需要正确的environment variables.

To be exactly correct only Pathvariable.

要完全正确,只有Path变量。

You need to find where you add JAVA_HOMEto path.

您需要找到添加JAVA_HOME到路径的位置。

Put it at first placeat Pathvariable:

把它在首位Path变量:

%JAVA_HOME%\bin;...

%JAVA_HOME%\bin;...

instead ...all other values of Path.

取而代之的是 的...所有其他值Path

I assume that JAVA_HOMEis defined as a variable and had correct value.

我假设它JAVA_HOME被定义为一个变量并且具有正确的值。

After this reopen console and check:

在此重新打开控制台并检查后:

java -version

java - 版本

回答by Jigar Joshi

JAVA_HOMEis environment variable that various application reads in their launcher script

JAVA_HOME是各种应用程序在其启动程序脚本中读取的环境变量

when you invoke javait looks up for all paths specified in your env variable named PATHand wherever the first match is it gets picked up

当您调用java它时,它会查找您命名的 env 变量中指定的所有路径,PATH以及第一个匹配项在哪里被拾取

so if you like command prompt to refer to jdk 6's Java append the path to PATH

因此,如果您希望命令提示符引用 jdk 6 的 Java,请将路径附加到 PATH

回答by Aakash

Check your PATHenvironment variable also. Your system is referring to latest Java installation through PATH variable.

PATH还要检查您的环境变量。您的系统通过 PATH 变量引用最新的 Java 安装。

回答by Sach141

I think in your pathvariable you have hardcoded the path to binfolder. it should always be %JAVA_HOME%/bin.

我认为在你的path变量中你已经硬编码了bin文件夹的路径。它应该总是%JAVA_HOME%/bin

So that it can pick path from JAVA_HOMEvariable and you don't need to change both the variables every time.

这样它就可以从JAVA_HOME变量中选择路径,并且您不需要每次都更改这两个变量。

回答by Prasad Kharkar

You need to add the path to jJAVA_HOME%/bindirectory in the pathvariable too. javacommand is located in %JAVA_HOME%/bin

您还需要jJAVA_HOME%/binpath变量中添加目录的路径。java命令位于%JAVA_HOME%/bin