Java works not well after upgrage Mac OS to Big Sur(v11.0.1)


I use Macbook pro to develop java app, it works well. While, after i upgraded mac os from 10.x to the latest version Big Sur, mvn clean package threw below exception:

[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 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 was changed after upgraded:


ingxingdeMacBook-Pro:bin kevin$ which 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
export PATH


Why which java output was changed after i upgraded Mac os, how to fix it.


Reason: In ~/.bash_profile, JAVA_HOME= $(/usr/libexec/java_home), after upgraded, $(/usr/libexec/java_home) link to /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java which doesn't exist in my disk, so jdk is missing.

Solution: I delete jdk in /Library/Java/JavaVirtualMachines and reinstall jdk8, and then set JAVA_HOME as:


instead of soft link and source ~/.bash_profile to let it work.

My full settings:

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

Now, jdk works, after mac os upgraded, it indeed update the soft link of $(/usr/libexec/java_home) and link to a not existed link, so i think you don't need to delete your jdk, just update env variables and re-open terminal to check if jdk reset correctly.

Posted on by Rollsbean

Relevant tags