Ant 在哪里设置它的“java.home”(它是错误的),它是否应该附加“/jre”?

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

Where does Ant set its 'java.home' (and is it wrong) and is it supposed to append '/jre'?

javaantcentosenvironment-variables

提问by ingyhere

Okay, I'm using Ant version 1.7.1 (default install) on CentOS 6.3:

好的,我在 CentOS 6.3 上使用 Ant 版本 1.7.1(默认安装):

[theuser@dev-ingyhere ~]$ ant -version
Apache Ant version 1.7.1 compiled on August 24 2010
[theuser@dev-ingyhere ~]$ cat /etc/*-release
CentOS release 6.3 (Final)

I have JAVA_HOMEset and I run ant:

我已经JAVA_HOME设置并运行ant

[theuser@dev-ingyhere ~]$ export JAVA_HOME=/usr/java/jdk1.7.0_17 ; echo $JAVA_HOME ;
/usr/java/jdk1.7.0_17
[theuser@dev-ingyhere ~]$ ant -diagnostics | grep java\.home
java.home : /usr/java/jdk1.7.0_17/jre

This is even more fun:

这更有趣:

[theuser@dev-ingyhere ~]$ export JAVA_HOME=/a/fools/folly ; echo $JAVA_HOME ; ant -diagnostics | grep java\.home
/a/fools/folly
java.home : /usr/java/jdk1.7.0_17/jre
[theuser@dev-ingyhere ~]$  env | grep JAVA
JAVA_HOME=/a/fools/folly 

So, I do get one thing -- apparently Oracle's Java 7 Javadoc for Class Systemis WRONG (aghast!) where it describes the java.homeSystem Property as the "Java installation directory." I know that because the Java(TM) Tutorials for System Propertiesdescribes the java.homeSystem Property as the "Installation directory for Java Runtime Environment (JRE)." In other words the JAVA_HOMEin the environment does not necessarily equal java.homein the JVM System Properties. (What sets that?!)

所以,我确实明白了一件事——显然Oracle 的 Java 7 Javadoc for Class System是错误的(令人震惊!),它将java.home系统属性描述为“Java 安装目录”。我知道这是因为Java(TM) 系统属性教程将系统属性描述java.home为“Java 运行时环境 (JRE) 的安装目录”。换句话说JAVA_HOME,环境java.home中的 JVM 系统属性中的不一定相同。(这是什么设定?!)

QUESTION: Where and how does Antget/set the system property java.home?

问题:在哪里以及如何Ant获取/设置系统属性java.home

回答by ingyhere

Really a JVM internals question

真的是 JVM 内部问题

Since Ant is just echoing the java.lang.System properties (see comment above under original post), this is really a JVM question. The Java HotSpot Virtual Machineis the core interpreter. Code is available online at hg.openjdk.java.net.

由于 Ant 只是回应 java.lang.System 属性(请参阅上面原始帖子下的评论),这确实是一个 JVM 问题。在的Java HotSpot虚拟机的核心解释。代码可在hg.openjdk.java.net在线获得

On line 309 of the C++ code for HotSpot (os_linux.cpp)there is a an init_system_properties_values()method in the osclass. It does some mild heuristics to kind of sniff out the location for a variable named home_pathwhich ends up being set to what Java users see as "java.home". Comments in the code indicate that '<java_home>/jre' is being formally specified as the java.lang.System property value for "java.home" (in the case of a JDK install).

在 HotSpot (os_linux.cpp) 的 C++ 代码的第 309 行init_system_properties_values()os类中有一个方法。它做了一些温和的启发式方法来嗅探一个名为的变量的位置,该变量home_path最终被设置为 Java 用户看到的“java.home”。代码中的注释表明“<java_home>/jre”被正式指定为“java.home”的 java.lang.System 属性值(在安装 JDK 的情况下)。

回答by eel ghEEz

I had a JDK installed on a Windows box in d:\jdk but running its d:\jdk\bin\java.exe with -XshowSettings showed its built-in java.home pointing to the system-wide JRE install in c:\Program Files\Java\jre1.8.0_91. I suspect that I corrupted my install by deleting d:\jdk\jre without understanding the role of a private JRE vs public JRE.

我在 d:\jdk 的 Windows 机器上安装了一个 JDK,但是使用 -XshowSettings 运行它的 d:\jdk\bin\java.exe 显示其内置的 java.home 指向 c:\ 中的系统范围的 JRE 安装Program Files\Java\jre1.8.0_91. 我怀疑我在不了解私有 JRE 与公共 JRE 的作用的情况下删除 d:\jdk\jre 破坏了我的安装。