gpt4 book ai didi

maven - JAVA_HOME 在 Maven 中不起作用

转载 作者:行者123 更新时间:2023-12-04 08:56:50 25 4
gpt4 key购买 nike

java安装在这个路径

$ which java
/usr/bin/java

mvn -version 出现此错误

$ mvn -version
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

我尝试了一些在线可用的解决方案,但这些对我不起作用。其中一些解决方案建议添加

$export JAVA_HOME = /usr/libexec/java_home 

或者

$export JAVA_HOME = $(/usr/libexec/java_home)

到下面的文件

~/.bashrc
~/.bash_profile
~/.profile

此外,当我尝试执行一个 shell 命令时,它会显示类似的错误

Error: JAVA_HOME is not defined correctly.
CARBON cannot execute /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java

最佳答案

在挣扎了将近一天之后,我发现 maven 没有从其中任何一个读取 $JAVA_HOME

 ~/.bashrc
~/.bash_profile
~/.profile
但它从 $JAVA_HOME 读取 ~/.mavenrc所以最后,当我添加

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home
~/.mavenrc 然后得到输出

mvn -v
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024m; support was removed in 8.0
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T15:39:06-04:00)
Maven home: /usr/local/Cellar/maven/3.5.0/libexec
Java version: 1.8.0_141, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre
Default locale: en_CA, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"

关于maven - JAVA_HOME 在 Maven 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45230150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com