你的Java位置是什么,以及如何将Maven指向它?

huangapple go评论89阅读模式
英文:

What is my java location and how can I point maven to it?

问题

我是一个没有任何Java经验的UI开发人员。然而,我有一个困扰。

> / % java --version
openjdk 15.0.1 2020-10-20
OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.1+9, mixed mode, sharing)

和:

> / % mvn -v
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /usr/local/Cellar/maven/3.8.6/libexec
Java version: 18.0.1.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/18.0.1.1/libexec/openjdk.jdk/Contents/Home
Default locale: en_RO, platform encoding: UTF-8
OS name: "mac os x", version: "12.4", arch: "x86_64", family: "mac"

我有一个问题,为什么Maven有另一个Java版本,如何使其指向Java 15?

我还尝试了这个:

> / % which java
/usr/bin/java
> / % cd /usr/bin/java
cd: not a directory: /usr/bin/java

我以为which命令会指向存储Java 15的位置,但这个路径似乎在我的计算机上不存在。

我还注意到我没有设置JAVA_HOME,它丢失了。

我很困惑,有人能帮我解决这个问题吗?

编辑:回应评论:

> / % ls -al /usr/bin/java
-rwxr-xr-x  52 root  wheel  168432 May 10  2022 /usr/bin/java
英文:

I am a UI dev with no experience in Java whatsoever. However, I have a dilema.

> / % java --version
openjdk 15.0.1 2020-10-20
OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.1+9, mixed mode, sharing)

and:

> / % mvn -v
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /usr/local/Cellar/maven/3.8.6/libexec
Java version: 18.0.1.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/18.0.1.1/libexec/openjdk.jdk/Contents/Home
Default locale: en_RO, platform encoding: UTF-8
OS name: "mac os x", version: "12.4", arch: "x86_64", family: "mac"

The question I have is, why does maven have another version of java, and how can I make it point to the java 15 ?

I also tried this:

> / % which java
/usr/bin/java
> / % cd /usr/bin/java
cd: not a directory: /usr/bin/java

I thought that the command which will point to me to the location where java 15 is stored, however that path does not seem to exist on my computer.

Another thing that I saw is that I do not hava JAVA_HOME set, it is missing.

I am very confused, can somebody help me surpass this issue please?

Edit: Response to the comments:

> / % ls -al /usr/bin/java
-rwxr-xr-x  52 root  wheel  168432 May 10  2022 /usr/bin/java

答案1

得分: 1

你应该更改你的 JAVA_HOME 变量或者选择以下替代方法:

export PATH=<YOUR_JRE_BIN_PATH>:${PATH}
mvn <MAVEN_ARGUMENTS>
英文:

You should change your JAVA_HOME variable or as alternative:

export PATH=&lt;YOUR_JRE_BIN_PATH&gt;:${PATH}
mvn &lt;MAVEN_ARGUMENTS&gt;

答案2

得分: 0

java命令中获取JAVA_HOME

JAVA_HOME=$(java -XshowSettings:properties -version 2>&1 | grep -E 'java\.home' | awk '{print $3}')

结果

java.home = /usr/lib64/jvm/java-11-openjdk-11

然后将JAVA_HOME导出为环境变量或在Maven命令中使用它:

export JAVA_HOME='/usr/lib64/jvm/java-11-openjdk-11'
mvn <something>
英文:

Get JAVA_HOME from the java command with

java -XshowSettings:properties -version 2&gt;&amp;1 | grep -E &#39;java\.home&#39;

Result

 java.home = /usr/lib64/jvm/java-11-openjdk-11

Then add an export for JAVA_HOME variable or use it on maven command as

JAVA_HOME=&#39;/usr/lib64/jvm/java-11-openjdk-11&#39; mvn &lt;something&gt;

huangapple
  • 本文由 发表于 2023年3月15日 19:01:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743836.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定