1

Maven suddenly stopped compiling with the error below. It was working this morning and I'm not sure what caused this.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ExampleProject: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Basic Information:
  • OS: Mac
  • Machine: MacBook Pro
  • Java: 1.8.0_201 (jdk8)
  • Maven: 3.8.1

What I tried:

  • Checked for existence of Java compiler
$ javac -version
javac 1.8.0_201
  • Check $JAVA_HOME : I got /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home, which is correct for Mac OS according to Maven's installation instructions

  • Added mvn to PATH before compiling

  • Reinstalled Maven 3.8.1

  • Reinstalled JDK8 and reset JAVA_HOME & added mvn to PATH again before compiling

  • Added sudo to my command. In fact before adding sudo, I was facing some sorta "failed to delete something" error.

  • Restarting my laptop without using the "Reopen windows...." option.

  • Adding the compiler option to pom.xml(I didn't need this when it was working this morning)

  • Running mvn -v give me the output below

    Maven home: /opt/apache-maven-3.8.3
    Java Version: 1.8.0_201, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/jre
    Default locale: en_GB, platform encoding: UTF-8
    OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
    
  • Running java -version gave me the output below:

    java version "1.8.0_201"
    Java (TM) SE Runtime Environment (build 1.8.0_201-b09)
    Java HotSpot (TM) 64-Bit Server VM (build 25.201.b09, mixed mode)
    
Additional Info:

I am not using any IDE like Eclipse/IntelliJ/NetBeans. Just purely on terminal. Please base your answers on this.

It seems like there are 2 versions of Maven on my system, probably due to the reinstall. But prior to the reinstall, this problem already started

Reference (I've tried the solutions in here too)

https://roufid.com/no-compiler-is-provided-in-this-environment/

Edit

  • I have already made sure that JAVA_HOME points to the JDK and not the JRE by consulting Maven's documentation
Beast
  • 370
  • 2
  • 14
  • The pointer to JAVA_HOME points to JRE and *not* to JDK...Also you are giving two different versions Maven the first one 3.8.1 while second output `mvn --version` shows 3.8.3 ? – khmarbaise Oct 06 '21 at 11:42
  • Thanks for reaching out. My Maven is version 3.8.3. As for JAVA_HOME, I followed Maven's installation guide https://maven.apache.org/install.html. Otherwise, what should JAVA_HOME be? And you are right that the versions are different(there's no typo there). Probably due to the reinstall. – Beast Oct 06 '21 at 11:47
  • The output shows `/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/jre` where the `jre` part is at the end... Try `/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home` ..instead... – khmarbaise Oct 06 '21 at 11:50
  • Hi @khmarbaise. The output you are talking about is from mvn -v. I already set JAVA_HOME to the one without the "jre" – Beast Oct 06 '21 at 11:53

1 Answers1

0

Maven needs javac to compile your project. Can you try javac -version and see if your able to get an output.

$ javac -version
javac 1.8.0_201

If not set your JAVA_HOME to JDK not to JRE. C:\Program Files\Java\jdk1.8.0_202

If you are still getting this error, try opening another terminal for the environment variable to reflect. And try.

Regards

  • Hi. Thanks for reaching out. I have tried that too. I have edited my post to add the part about `javac` – Beast Oct 06 '21 at 12:52