[英]Java_home in Maven
When I ran mvn -version
, I noticed the java_home
points to ...jdk\\jre
(as shown below). 当我运行
mvn -version
,我注意到java_home
指向...jdk\\jre
(如下所示)。 Is that wrong? 那是错的吗? Isn't it supposed to point to
...\\jdk.xyz
(without the \\jre
)? 是不是应该指向
...\\jdk.xyz
(没有\\jre
)? If so, how do I reset it? 如果是这样,我该如何重置它? (In global
%java_home%
points to the jdk
directory) (在全局
%java_home%
指向jdk
目录)
C:\Users\Owner>mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-06 15:16:01-0400)
Java version: 1.7.0_17
Java home: C:\Program Files\Java\jdk1.7.0_17\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
No, it's not wrong. 不,这没错。 It is pointing to the JRE used by your JDK, which is what it's supposed to.
它指向JDK使用的JRE,这是它应该的。 If you print out
JAVA_HOME
outside maven, it should print correctly: 如果你在maven外面打印出
JAVA_HOME
,它应该正确打印:
C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.7.0_07
C:\>mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 10:44:56+0200)
Maven home: C:\APPS\apache-maven-3.0.4\bin\..
Java version: 1.7.0_07, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_07\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
C:\>
So basically JAVA_HOME needs to point to a JDK installation (maven needs the tools.jar) but maven actually uses the jre within the JDK to run itself. 所以基本上JAVA_HOME需要指向JDK安装(maven需要tools.jar),但是maven实际上使用JDK中的jre来运行自己。
When using mvn -version
, maven uses java internal java.home property, as can be seen from source code : 当使用
mvn -version
,maven使用java内部java.home属性,从源代码可以看出:
version.append( "Java home: " + System.getProperty( "java.home", "<unknown java home>" ) ).append( LS );
This property is not the same thing as JAVA_HOME environment setting, so it might fool you. 此属性与JAVA_HOME环境设置不同,因此可能会欺骗您。 It is actually dynamic property showing you which JRE is running your code.
它实际上是动态属性,显示哪个JRE正在运行您的代码。 If you compile and execute a Test.java test class printing the same, you can see that if your JAVA_HOME points to a JDK, the value of java.home is not equal to your JAVA_HOME.
如果您编译并执行打印相同的Test.java测试类,您可以看到如果您的JAVA_HOME指向JDK,则java.home的值不等于您的JAVA_HOME。 This is expected.
这是预料之中的。
What's the difference between JAVA_HOME and java.home?
JAVA_HOME和java.home有什么区别?
JAVA_HOME is the JDK install directory, eg, C:\\jdk5.
JAVA_HOME是JDK安装目录,例如C:\\ jdk5。 It's meant to be set as an environment variable and referenced in Windows batch files or Unix scripts.
它应该设置为环境变量,并在Windows批处理文件或Unix脚本中引用。 I always have it in my Windows Control Panel and .tcsh files,along with other common environment variables.
我总是在Windows控制面板和.tcsh文件中以及其他常见环境变量中使用它。 Some Java applications use the name jdk.home for this purpose, which I think is a better name.
一些Java应用程序使用名称jdk.home来实现此目的,我认为这是一个更好的名称。 But JAVA_HOME has been used since the beginning and is now a convention.
但是JAVA_HOME从一开始就被使用,现在已经成为一种惯例。
java.home is the JRE install directory, eg, C:\\jdk5\\jre, or C:\\Program Files\\Java\\jre1.5.0_06.
java.home是JRE安装目录,例如C:\\ jdk5 \\ jre,或C:\\ Program Files \\ Java \\ jre1.5.0_06。 Unlike JAVA_HOME, I never seen java.home as an environment variable.
与JAVA_HOME不同,我从未将java.home视为环境变量。 java.home is a build-in Java system property, whose value is the JRE install directory.
java.home是内置Java系统属性,其值为JRE安装目录。 Since all Java system properties are also exposed as Ant build properties, you can also use ${java.home} in build files.
由于所有Java系统属性也作为Ant构建属性公开,因此您还可以在构建文件中使用$ {java.home}。
Would jre.home be a better name?
jre.home会是一个更好的名字吗? Maybe, but I don't think Sun will change it.
也许,但我不认为Sun会改变它。
You can see that maven uses JAVA_HOME on mvn.bat: 你可以看到maven在mvn.bat上使用JAVA_HOME:
:endInit
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
..
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR% ..
And if you want to make sure, you can comment out "@echo off" statement in mvn.bat, so you can see that it is being used. 如果你想确定,你可以在mvn.bat中注释掉“@echo off”语句,这样你就可以看到它正被使用。
TL;DR: Based on the information you've given, your configuration is correct, no need to change anything. TL; DR:根据您提供的信息,您的配置是正确的,无需更改任何内容。
Edit: thanks to this thread, there was also an issue about this being confusing , which resulted in change of output for Maven version 3.5.4. 编辑:多亏了这个帖子,还有一个问题就是混乱 ,这导致了Maven版本3.5.4的输出更改。
What helped me debugging mvn/jdk issues is to set this before running mvn: set MAVEN_BATCH_ECHO=on
帮助我调试mvn / jdk问题的是在运行mvn之前设置它:
set MAVEN_BATCH_ECHO=on
You get verbose output (on windows), including info how Maven picks java. 你得到详细的输出(在Windows上),包括Maven如何选择java的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.