Maven points Java home to JRE install directory instead of JDK's

Posted by Echo Yuan on August 15, 2017

是在看另外一个问题maven-bootclasspath-multiple-jars时注意到的,即${java.home}\lib\rt.jar中的java.home到底指代哪个目录呢?

mvn -version看下效果

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /Users/echo/Documents/frameworks/apache/apache-maven-3.3.9
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.3", arch: "x86_64", family: "mac"

嗯,java.home指到了jre目录下。

再看看echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

Google了下,stackoverflow上的这个回答说的很好,它里边还引用了这篇博客的内容,写的也很棒。

去Oracle的官方文档上看的话,这里https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html的描述

“java.home” Installation directory for Java Runtime Environment (JRE)

和这里http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#getProperties()的有些出入

java.home Java installation directory

实际在代码里打印System.getProperty("java.home")的结果

/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre

所以,Maven不能背这个锅,哈哈~ 人家在这里也说的很明白

Ensure JAVA_HOME environment variable is set and points to your JDK installation