简体   繁体   English

JAVA_HOME 设置但不生效

[英]JAVA_HOME set but not taking effect

在此处输入图像描述

As depicted in above image java home is set and is being echoed but when i check for version it gives me latest version.如上图所示,java home 已设置并正在回显,但是当我检查版本时,它给了我最新版本。 Already restarted the command prompt after setting env variable.设置环境变量后已经重新启动命令提示符。 OS is Windows 7操作系统是 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;

I had the same trouble and I solved it with the following steps:我遇到了同样的麻烦,我通过以下步骤解决了它:

You need the correct environment variables.您需要正确的环境变量。

To be exactly correct, you only need to set the Path variable.要完全正确,您只需要设置Path变量。

You need to find where you add %JAVA_HOME%\bin to the path.您需要找到将%JAVA_HOME%\bin添加到路径的位置。

Put it at first place in the Path variable:把它放在Path变量的第一位:

%JAVA_HOME%\bin;... 

where ... represents all other values of Path .其中...表示Path的所有其他值。

I assume that JAVA_HOME is defined as a variable and had the correct value.我假设JAVA_HOME被定义为一个变量并且具有正确的值。

After this reopen console and check:重新打开控制台后,检查:

java -version

JAVA_HOME is environment variable that various application reads in their launcher script JAVA_HOME是各种应用程序在其启动器脚本中读取的环境变量

when you invoke java it looks up for all paths specified in your env variable named PATH and wherever the first match is it gets picked up当您调用java时,它会查找名为PATH的 env 变量中指定的所有路径,并且无论第一个匹配项在哪里,它都会被拾取

so if you like command prompt to refer to jdk 6's Java append the path to PATH因此,如果您喜欢命令提示符来引用 jdk 6 的 Java,请将路径附加到PATH

You need to add the path to jJAVA_HOME%/bin directory in the path variable too.您还需要在path变量中添加jJAVA_HOME%/bin目录的路径。 java command is located in %JAVA_HOME%/bin java命令位于%JAVA_HOME%/bin

Check your PATH environment variable also.还要检查您的PATH环境变量。 Your system is referring to latest Java installation through PATH variable.您的系统通过 PATH 变量引用最新的 Java 安装。

I think in your path variable you have hardcoded the path to bin folder.我认为在您的path变量中,您已经硬编码了bin文件夹的路径。 it should always be %JAVA_HOME%/bin .它应该始终是%JAVA_HOME%/bin

So that it can pick path from JAVA_HOME variable and you don't need to change both the variables every time.这样它就可以从JAVA_HOME变量中选择路径,并且您不需要每次都更改这两个变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM