Roufid

3 ways to solve the Maven error : No compiler is provided in this environment.

Maven

Problem

You may face the below Maven error while running a Maven build :

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Solution

Your JAVA_HOME environment variable or your Eclipse IDE are pointing to a JRE rather than a JDK. You must set a correct compiler in your environment and below 3 ways to perform it:

  1. Refer the JAVA_HOME to a JDK
  2. Maven on Eclipse : The correct configuration
  3. Fix the problem in the pom.xml

1- Refer the JAVA_HOME to a JDK

If you are running Maven on command line, it is very likely that your Maven environment is not configured correctly. In fact, Maven relies on the JAVA_HOME environment variable to use the right compiler. JAVA_HOME must refer to a JDK (JAVA Development Kit) and not a JRE (Java Runtime Environment). See the difference between a JDK and a JRE

To check what your Maven uses, open a command line and type:

Output:

JAVA_HOME environment variable

Verify that JAVA_HOME refers to a JDK home and not a JRE. It refers to a JRE in the previous example.

Below how to update the value of JAVA_HOME:

On Windows:

If you are using command line you can set the variable before running the build as following:

On Unix:

2- Running Maven in Eclipse

If you are running Maven from your IDE you must check that your environment is using a JDK rather than a JRE. Below how to perform the check:

TheNo compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? Maven error will disappear.

3- Adding the configuration in the pom.xml

Another solution is to fork the maven-compiler-plugin and set the full path to the correct Java compiler as blow :

References