java maven 如何知道 JAVA_HOME 在 Ubuntu 中设置为环境变量

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

How does maven know JAVA_HOME set as an environment variable inUbuntu

javamavenenvironment-variablesubuntu-14.04

提问by crackerplace

When I type mvn --version in ubuntu from the terminal(ubuntu),I get the below output.

当我从终端(ubuntu)在 ubuntu 中键入 mvn --version 时,我得到以下输出。

Warning: JAVA_HOME environment variable is not set.
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-32-generic", arch: "amd64", family:     "unix"

When I did not set any JAVA_HOME environment variable , how is maven getting the java home installed path.Is it trying to find this path from the /usr/bin/java command which is installed in my system and if so why is it taking the path till jre.

当我没有设置任何 JAVA_HOME 环境变量时,maven 如何获取 java home 安装路径。它是否试图从安装在我系统中的 /usr/bin/java 命令中找到这个路径,如果是这样,为什么它需要直到 jre 的路径。

P.S : Also I could not find any java path in any maven config.

PS:此外,我在任何 Maven 配置中都找不到任何 java 路径。

Thanks.

谢谢。

采纳答案by Zakaria

As showed in the CLIReportingUtils.java(the maven class that retrieves the Java Home), the value comes from the following call :

CLIReportingUtils.java(检索 Java Home 的 maven 类)所示,该值来自以下调用:

System.getProperty( "java.home", "<unknown java home>" )

The java.homeis for the JRE unlike the JAVA_HOMEwhich is for the JDK. So Maven is displaying the JRE home.

java.home是不像的JREJAVA_HOME这对JDK。因此 Maven 正在显示 JRE 主页。

回答by hinneLinks

I would say there is a difference between JAVA_HOMEenvironment variable and the output Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre. The latter is just the output of the installation directory see here.

我会说JAVA_HOME环境变量和输出之间存在差异 Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre。后者只是安装目录的输出见这里

So maven will run Java in background and java knows where its installed.

因此 maven 将在后台运行 Java,而 java 知道它的安装位置。

回答by crackerplace

I think,I understand it now.In the maven script i.e (usr/share/maven/bin/mvn) they are trying to find the java installed using a variety of options.

我想,我现在明白了。在 maven 脚本 ie (usr/share/maven/bin/mvn) 中,他们试图找到使用各种选项安装的 java。

So at one place they are doing the below

所以在一个地方他们正在做下面的事情

JAVACMD="`which java`"

And now in my system "which java" points to the below

现在在我的系统中“哪个 java”指向下面

java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

Hope this is how its getting the java path.

希望这是它获取java路径的方式。