Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac os Big Sur | No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Tags:

java

maven

I am getting this error on the screenshot and I have seen other posts about it, however, the fixes provided are mainly for Windows, so whatever I tried did not fix the issue on my Mac.

Currently, when I run /usr/libexec/java_home it points me here: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

So when running a maven project it throughs message like this: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

So, I am wondering if the location of JAVA_HOME is incorrect, and if so how can I fix it? Sorry, if asking something obvious questions, but I am new to this.

I would really appreciate your help.

enter image description here

like image 226
Roman Belov Avatar asked Jan 26 '21 15:01

Roman Belov


People also ask

How do you fix no compiler is provided in this environment Perhaps you are running on a JRE rather than a JDK in Intellij?

To fix the issue install any JDK on your system and make sure the bin subdirectory of the JDK home directory is added to PATH environment. You may also want to set JAVA_HOME environment variable pointing to this JDK installation home directory. To verify that it works run java -version in the system Terminal.

Can we use JRE instead of JDK?

Maven requires Eclipse using a JDK, i.e. Java Development Kit, instead of a Java Runtime Environment (JRE). The main difference is that a JDK also contains a Java Compiler and other tools to develop Java Code, while the JRE is only able to run compiled Java applications.

Is there a compiler for Mac OS Big Sur?

- Stack Overflow Mac os Big Sur | No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? Bookmark this question. Show activity on this post.

What's new in macOS Big Sur?

macOS Big Sur 4+ Apple Free Screenshots Description macOS Big Sur elevates the world's most advanced desktop operating system to a new level of power and beauty. Experience Mac to the fullest with a refined new design. Enjoy the biggest Safari update ever. Discover new features for Maps and Messages.

What are the most common macOS Big Sur problems?

One common macOS Big Sur problem that people have encountered is that macOS 11 fails to download, with some users seeing an error message that says "Installation failed." Others, on the other hand, are seeing "The network connection was lost" error messages when they try to download macOS Big Sur. That's not all, either.

How to install macOS Big Sur ISO file on Windows 10/11?

To add the macOS Big Sur ISO file to the guest system you created, select Use ISO Image File on the CD/DVD (SATA) device in the hardware settings window and click Browse. Select the macOS 11 ISO file you downloaded to your computer and click Open.


4 Answers

I meet the same question as yours.
This solution (Build failure run "mvn clean install". I just upgraded Big Sur) is to remove useless jre.
Mine is to give mvn shell a correct java_home.

Solution - edit mvn bash

Step 1: Check how to filter your target java by /usr/libexec/java_home

When I run command /usr/libexec/java_home -V

I can see 2 virtual machines

MacBook-Pro:bin charles$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    1.8.251.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_251 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

My default return value of /usr/libexec/java_home is my jre path such as
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

But I can change the return jdk path
/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home

if I run command
/usr/libexec/java_home -v1.8.0

Step 2: Update mvn shell

Find following lines in mvn shell


if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
    #
    # Apple JDKs
    #
    export JAVA_HOME=`/usr/libexec/java_home`
fi

Because I can use usr/libexec/java_home -v1.8.0 to make sure system using jdk, I update my shell as

if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
    #
    # Apple JDKs
    #
    export JAVA_HOME=`/usr/libexec/java_home -v1.8.0`
fi

And then, it works.

How to check difference

mvn -version

Before I update my mvn, I will see

MacBook-Pro:~ charles$ mvn -version
Apache Maven ........
Maven home: ........
Java version: 1.8.0_251, vendor: Oracle Corporation
Java home: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Default locale: zh_TW, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

After I update my mvn, I can see the result

MacBook-Pro:~ charles$ mvn -version
Apache Maven ........
Maven home: .......
Java version: 1.8.0_251, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre
Default locale: zh_TW, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

Though java home display as jre path, but the jre is sub-folder inside of jdk. It's ok.

like image 68
Charles Wu Avatar answered Nov 10 '22 17:11

Charles Wu


The default JRE comes with Mac is /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

% /usr/libexec/java_home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

I have installed JDK using a dmg file. Even after passing the JAVA_HOME to the new path from bashrc (/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home), it was not taking.

To list the avaiable java installations

% /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    1.8.311.11 (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

In order to point to your JDK, just do the below.

% cd /Library/Internet\ Plug-Ins
% ls
JavaAppletPlugin.plugin
$ sudo mv JavaAppletPlugin.plugin JavaAppletPlugin.plugin-backup 

After that, if you run the command

% /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home

Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time that you perform an update of the OS.

like image 27
Gajapathi Kimidi Avatar answered Nov 10 '22 19:11

Gajapathi Kimidi


I was having the same issue, and could not fix it using the answers provided, maven kept using the default jre and I was always getting the "No compiler error..". I managed to solve it setting the JAVA_HOME environment, so in my case I used the command:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_331.jdk/Contents/Home

After this command, the command mvn -v now outputs:

Maven home: /opt/homebrew/Cellar/maven/3.8.5/libexec Java version: 1.8.0_331, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_331.jdk/Contents/Home/jre

Although it says /jre, the command that was failing, "mvn clean package -D skipTests", now executes properly.

So hope it helps somebody.

like image 41
GAlonso Avatar answered Nov 10 '22 18:11

GAlonso


Run the command to list the available java installations:

$ /usr/libexec/java_home -V

Matching Java Virtual Machines (2):

1.8.251.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_251 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home

Check the default return value of the following command which is jre path in my case:

$/usr/libexec/java_home

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

Run the command to get JDK path:

$ /usr/libexec/java_home -v1.8.0

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

Add the following line in .bash_profile file:

export JAVA_HOME=$(/usr/libexec/java_home -v1.8.0)

like image 22
tharun Avatar answered Nov 10 '22 18:11

tharun