Build failure run "mvn clean install". I just upgraded Big Sur

Viewed 10329

mvn clean install building failure

  [INFO] Total time:  1.911 s
    [INFO] Finished at: 2020-11-14T19:07:37+08:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project es-starter: Compilation failure
    [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    [ERROR]
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Java & Maven environment

➜

      ~ which java
    /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
    ➜  ~ mvn -v
    Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
    Maven home: /Users/munan/Documents/work/develop/maven/apache-maven-3.6.1
    Java version: 1.8.0_192, vendor: Oracle Corporation, runtime: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    Default locale: zh_CN, platform encoding: UTF-8
    OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

It seems that there is no problem with the environment. So where is the problem that caused the build to fail?

9 Answers

BigSur added JRE path for some reason and I uninstalled the JRE as I needed the JDK (and not JRE) and it worked.

  1. Go to /Library/Internet Plug-Ins.
  2. Remove the JavaAppletPlugin.plugin directory by executing the rm command as a root user or by using the sudo tool.
  3. Go to /Library/PreferencePanes.
  4. Remove JavaControlPanel.prefpane by executing the rm command as a root user or by using the sudo tool.

I was facing the same issue after updating my Mac to Big Sur!

BigSur added JRE path for some reason, and higher priority than yourself JDK。

Heres my solution:

First:

/usr/libexec/java_home -V

then maybe you will get:

Matching Java Virtual Machines (2):
    1.8.202.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_202 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

so the second is our's real JDK. Just edit the JAVA_HOME in your bash profile.

vim ~/.zshrc
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home"
source vim ~/.zshrc
echo $JAVA_HOME

Then it will works! enjoy Bug Sur!

Or you can reinstall jdk8 by this cmd:

brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8

I was facing the same issue after updating my Mac to Big Sur! So I set my JAVA_HOME env variable and now everything is back to its business. Open the terminal and hit the below commands to solve it yourself.


$ vim .bash_profile 
export JAVA_HOME=$(/usr/libexec/java_home)
$ source .bash_profile
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

Check your java_home by running:

/usr/libexec/java_home -V

Read more about it here - https://mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/

If you were already using something like export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) in your bash profile, update the command by specifying more of the java version.

For instance, when I do /usr/libexec/java_home -V, I get:

Matching Java Virtual Machines (3):
11.0.3 (x86_64) "Oracle Corporation" - "Java SE 11.0.3" /Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home
1.8.231.11 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_181 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home

I updated my command to export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0) and then JAVA_HOME is set correctly.

you JAVA_HOME contains JRE path , Please use JDK (The JDK includes the JRE).

It will resolve your issue.

Big Sur defaults to zsh, while most of the comments here refer to bash.

How I fixed it on my Big Sur with zsh:

  1. Edit ~/.zshrc
  2. Find (or add) export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)
  3. Restart the terminal
  4. echo $JAVA_HOME, make sure it prints path to JDK (and not apple's JRE)

-v 1.8 didn't work for me, cause Apple's JRE was 1.8 too, so I needed 1.8.0 explicitly.

Hey this is coming in the error [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

you have to switch to openJdk to do maven clean and install 1st you have to download it you can find it easily. In eclipse you can right click on the project then build path then set the openJDK in libraries tab. After this these error will not come but after each FMP it may switch back to jre. Hope the help

I had the similar issue after upgrading to Big Sur. Deleting the JRE as suggested by Anudeep worked

my macos is Monterey 12.4
I use mvn -version to search my maven‘s runtime config is:

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

I think , may be not use my jre..

  1. use /usr/libexec/java_home to copy your's java home
  2. then , vim ~/.zshrc
  3. insert export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home" this java home is mine,you should use yours.
  4. source ~/.zshrc for refresh config and echo $JAVA_HOM for check your java home is right
  5. cd /Library/Internet Plug-Ins and sudo mv JavaAppletPlugin.plugin JavaAppletPlugin.plugin-backup
  6. /usr/libexec/java_home

and then use mvn -version to search my new maven‘s runtime config is:

/Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home/jre
Related