gpt4 book ai didi

将 Macos 升级到 Big Sur(v11.0.1) 后,Java 无法正常运行

转载 作者:行者123 更新时间:2023-12-05 09:36:51 25 4
gpt4 key购买 nike

背景:

我使用 Macbook pro 开发 java 应用程序,它运行良好。而在我将 mac os 从 10.x 升级到最新版本 Big Sur 后,mvn clean package 抛出了以下异常:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project dq-common: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/../lib/tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.

java -version:

jingxingdeMacBook-Pro:~ kevin$ java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
jingxingdeMacBook-Pro:dt-center-valid-4.0 kevin$

升级后更改了哪些java:

之前:

ingxingdeMacBook-Pro:bin kevin$ which java
/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/bin/java

现在:

jingxingdeMacBook-Pro:~ kevin$ which java
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java

cat ~/.bash_profile:

jingxingdeMacBook-Pro:~ kevin$ cat ~/.bash_profile
export M2_HOME=/usr/local/apache-maven-3.6.3
#Mac OSX 10.5 or later version need this configure
export JAVA_HOME=$(/usr/libexec/java_home)
#export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
export MySQL_HOME=/usr/local/mysql
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export HADOOP_HOME=/Users/kevin/Desktop/Developments/Software/hadoop-3.3.0
PATH=$M2_HOME/bin:$JAVA_HOME/bin:$MySQL_HOME/bin:$HADOOP_HOME/bin:$PATH:.
export PATH

问题:

为什么在我升级 Mac os 后 which java 输出发生了变化,如何修复它。

最佳答案

原因:~/.bash_profile中,JAVA_HOME= $(/usr/libexec/java_home),升级后,$(/usr/libexec/java_home) 链接到 /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java 我的磁盘中不存在,所以缺少 jdk。

解决方法:我删除了/Library/Java/JavaVirtualMachines中的jdk,重新安装jdk8,然后设置JAVA_HOME为:

/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home

而不是软链接(soft link)和 source ~/.bash_profile 让它工作。

我的完整设置:

kevinMacBook-Pro:bin kevin$ cat ~/.bash_profile
export M2_HOME=/usr/local/apache-maven-3.6.3
#Mac OSX 10.5 or later version need this configure
#export JAVA_HOME=$(/usr/libexec/java_home)
#Mac 11 need this configure
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
export MySQL_HOME=/usr/local/mysql

现在,jdk 工作了,在 mac os 升级后,它确实更新了 $(/usr/libexec/java_home) 的软链接(soft link)并链接到一个不存在的链接,所以我认为你不不需要删除您的 jdk,只需更新环境变量重新打开终端以检查 jdk 是否正确重置。

关于将 Macos 升级到 Big Sur(v11.0.1) 后,Java 无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64875451/

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