java 错误:JAVA_HOME 设置为无效目录

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

Error: JAVA_HOME is set to an invalid directory

javamavenjava-home

提问by MrPencil

I am trying to get maven installation to work but I am always getting this error

我试图让 maven 安装工作,但我总是收到这个错误

C:\Windows\System32>mvn --version
Error: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "C:\Program Files\Java\jdk1.7.0_51;"
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

C:\Windows\System32>mvn --version
错误:JAVA_HOME 设置为无效目录。
JAVA_HOME = "C:\Program Files\Java\jdk1.7.0_51;"
请在您的环境中设置 JAVA_HOME 变量以匹配您的 Java 安装位置。

I know that the error says every thing but I have tried everything here. I have the following setting:

我知道错误说明了一切,但我在这里尝试了一切。我有以下设置:

System Variables:

系统变量:

M2_HOME:C:\Program Files\Apache Software Foundation\apache-maven-3.3.3

M2_HOME:C:\Program Files\Apache Software Foundation\apache-maven-3.3.3

M2:%M2_HOME%\bin

M2:%M2_HOME%\bin

JAVA_HOME:C:\Program Files\Java\jdk1.7.0_51

JAVA_HOME:C:\Program Files\Java\jdk1.7.0_51

I added the whole path maybe it is interested someone. please take a look at the last part.

我添加了整个路径,也许有人感兴趣。请看最后一部分。

Path:

小路:

C:\Program Files\Java\jdk1.7.0_51\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\git\cmd;%M2%;%JAVA_HOME%\bin;

Path interested part:

路径感兴趣的部分:

%M2%;%JAVA_HOME%\bin;

I have tried it by deleting the %JAVA_HOME%\bin;too but it does not work since I have this path by the SDK installation at the start of the path C:\Program Files\Java\jdk1.7.0_51\bin

我也尝试过删除它,%JAVA_HOME%\bin;但它不起作用,因为我在路径开头的 SDK 安装中有这个路径 C:\Program Files\Java\jdk1.7.0_51\bin

I have tried to add the setting to the user variables and it does not work.

我试图将设置添加到用户变量中,但它不起作用。

回答by Jesper

JAVA_HOME = "C:\Program Files\Java\jdk1.7.0_51;"

JAVA_HOME = "C:\Program Files\Java\jdk1.7.0_51;"

Maven says that there is a semi-colon after the directory name in the JAVA_HOMEenvironment variable. Remove the semi-colon.

Maven 说JAVA_HOME环境变量中的目录名后面有一个分号。删除分号。

回答by TubusMan

you shoud have both maven and java home defined in the same System Variable ...

你应该在同一个系统变量中定义了 maven 和 java home ......

回答by Denis Kozlov

Try Rename M2_HOMEat MAVEN_HOMEAlso change M2: %MAVEN_HOME%\bin

尝试在MAVEN_HOME重命名M2_HOME同时更改M2: %MAVEN_HOME%\bin

回答by Ewerton

For me, the trick is to close and open another CMD window, to check if ir worked

对我来说,诀窍是关闭并打开另一个 CMD 窗口,以检查它们是否有效