Maven中的Java_home [英] Java_home in Maven

查看:474
本文介绍了Maven中的Java_home的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 mvn -version 时,我注意到 java_home 指向 .. .jdk \ jre (如下图所示)。
那是错的吗?它不应该指向 ... \ jdk.x.y.z (没有 \ jre )?
如果是这样,我该如何重置它? (在全局%java_home%指向 jdk 目录)

When I ran mvn -version, I noticed the java_home points to ...jdk\jre (as shown below). Is that wrong? Isn't it supposed to point to ...\jdk.x.y.z (without the \jre)? If so, how do I reset it? (In global %java_home% points to the jdk directory)

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"


推荐答案

不,这没错。它指向JDK使用的JRE,这是它应该的。如果您在maven外打印 JAVA_HOME ,它应该打印正确:

No, it's not wrong. It is pointing to the JRE used by your JDK, which is what it's supposed to. If you print out JAVA_HOME outside maven, it should print correctly:

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:\>

所以基本上JAVA_HOME需要指向JDK安装(maven需要tools.jar)但实际上是maven使用JDK中的jre来运行自己。

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.

当使用 mvn -version 时,maven使用java内部java。家庭财产,从源代码

When using mvn -version, maven uses java internal java.home property, as can be seen from source code:

version.append( "Java home: " + System.getProperty( "java.home", "<unknown java home>" ) ).append( LS );

此属性与JAVA_HOME环境设置不同,所以它可能会欺骗你。它实际上是动态属性,显示哪个JRE正在运行您的代码。如果您编译并执行打印相同的Test.java测试类,您可以看到如果您的JAVA_HOME指向JDK,则java.home的值不等于您的JAVA_HOME。这是预期的。

This property is not the same thing as JAVA_HOME environment setting, so it might fool you. It is actually dynamic property showing you which JRE is running your code. 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. This is expected.

引用这个


JAVA_HOME和java.home有什么区别?

What's the difference between JAVA_HOME and java.home?

JAVA_HOME是JDK安装目录,例如C:\ jdk5。这意味着将
设置为环境变量,并在Windows批处理文件或
Unix脚本中引用。我总是在Windows控制面板和.tcsh
文件中以及其他常见环境变量中使用它。一些Java
应用程序使用名称jdk.home来实现此目的,我认为
是一个更好的名称。但是JAVA_HOME从一开始就被使用,现在是
惯例。

JAVA_HOME is the JDK install directory, e.g., C:\jdk5. It's meant to be set as an environment variable and referenced in Windows batch files or Unix scripts. I always have it in my Windows Control Panel and .tcsh files,along with other common environment variables. Some Java applications use the name jdk.home for this purpose, which I think is a better name. But JAVA_HOME has been used since the beginning and is now a convention.

java.home是JRE安装目录,例如C:\ jdk5 \\ \\ jre,或
C:\Program Files\Java \ jre1.5.0_06。与JAVA_HOME不同,我从未见过
java.home作为环境变量。 java.home是一个内置的Java
系统属性,其值为JRE安装目录。由于所有
Java系统属性也作为Ant构建属性公开,因此
也可以在构建文件中使用$ {java.home}。

java.home is the JRE install directory, e.g., C:\jdk5\jre, or C:\Program Files\Java\jre1.5.0_06. Unlike JAVA_HOME, I never seen java.home as an environment variable. java.home is a build-in Java system property, whose value is the JRE install directory. Since all Java system properties are also exposed as Ant build properties, you can also use ${java.home} in build files.

jre.home会是一个更好的名字吗?也许吧,但我不认为Sun会以
来改变它。

Would jre.home be a better name? Maybe, but I don't think Sun will change it.

你可以看到maven在mvn上使用JAVA_HOME。 bat:

You can see that maven uses JAVA_HOME on mvn.bat:

:endInit
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
..
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR% ..

如果你想确定,你可以在mvn.bat中注释掉@echo off语句,这样你就可以看到它正被使用。

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.

TL; DR:根据您提供的信息,您的配置是正确的,无需更改任何内容。

TL;DR: Based on the information you've given, your configuration is correct, no need to change anything.

编辑:多亏了这个帖子,还有关于这个令人困惑的问题,导致Maven版本3.5.4的输出更改。

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中的Java_home的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆