java在将macos升级到BigSur(v11.0.1)后工作不好

a7qyws3x  于 2021-07-11  发布在  Java
关注(0)|答案(2)|浏览(651)

背景:
我用MacBookPro开发java应用程序,效果很好。而在我将MacOS从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$
``` which 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

问题:
为什么? `which java` 我升级mac操作系统后,输出发生了变化,如何修复它。
7z5jn7bk

7z5jn7bk1#

原因:在 ~/.bash_profile , JAVA_HOME= $(/usr/libexec/java_home) ,升级后,$(/usr/libexec/java\u home)链接到 /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java 在我的磁盘中不存在,所以jdk丢失了。
解决方案:在中删除jdk /Library/Java/JavaVirtualMachines 重新安装jdk8,然后设置 JAVA_HOME 作为: /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home 而不是软链接和 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工作了,在macos升级之后,它确实更新了 $(/usr/libexec/java_home) 并且链接到一个不存在的链接,所以我认为您不需要删除您的jdk,只需更新env变量并重新打开终端来检查jdk是否正确重置。

i1icjdpr

i1icjdpr2#

找到你的jdk位置(我的是 /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home ).
在终端 vim ~/.bash_profile (分别。以您习惯的任何方式编辑文件)
添加一行导出jdk位置(在我的例子中是 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home )
在终端 source ~/.bash_profile 在终端 echo $JAVA_HOME 确保环境变量设置正确

相关问题