背景:
我使用Macbook pro来开发java应用程序,它运行得很好。在我将mac从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/javacat ~/.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后被更改,如何修复它。
发布于 2020-11-18 02:27:41
原因: In ~/.bash_profile,JAVA_HOME= $(/usr/libexec/java_home),升级后,$(/usr/libexec/java_home)链接到磁盘中不存在的/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java,所以jdk丢失了。
解决方案:I删除/Library/Java/JavaVirtualMachines中的jdk并重新安装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可以工作了,在mac升级之后,它确实更新了$(/usr/libexec/java_home)的软链接并链接到一个不存在的链接,所以我认为您不需要删除jdk,只需要删除更新env变量和重新打开的终端来检查jdk重置是否正确。
发布于 2020-12-28 12:48:06
查找您的JDK位置(我的位置是/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home)。
vim ~/.bash_profile (resp. )以您习惯的任何方式编辑该文件) export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home)source ~/.bash_profileecho $JAVA_HOME,以确保正确设置环境变量)
https://stackoverflow.com/questions/64875451
复制相似问题