简体   繁体   English

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

[英]How does maven know JAVA_HOME set as an environment variable inUbuntu

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。

PS : Also I could not find any java path in any maven config. PS:我也找不到任何maven配置中的任何java路径。

Thanks. 谢谢。

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.home is for the JRE unlike the JAVA_HOME which is for the JDK. java.home用于JRE,不同于JDK的JAVA_HOME So Maven is displaying the JRE home. 所以Maven正在展示JRE主页。

I would say there is a difference between JAVA_HOME environment variable and the output Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre . 我想说JAVA_HOME环境变量和输出Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre之间有区别Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre The latter is just the output of the installation directory see here . 后者只是安装目录的输出, 请看这里

So maven will run Java in background and java knows where its installed. 所以maven将在后台运行Java,java知道它的安装位置。

I think,I understand it now.In the maven script ie (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路径的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM