Error: JAVA_HOME is set to an invalid directory.解决办法

安装maven时提示下列错误

Error: JAVA_HOME is set to an invalid directory.
JAVA_HOME = "Error: JAVA_HOME not found in your environment." 
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

在c盘目录的命令行下执行

C:\>SET JAVA_HOME=path\to\your\jdk

记住后面不能有\bin。随后执行

mvn --version

如果显示

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: ...\bin\..
Java version: 1.8.0_101, vendor: Oracle Corporation
Java home: ...\jdk1.8.0_101\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"

这样就成功啦

你可能感兴趣的:(Error: JAVA_HOME is set to an invalid directory.解决办法)