Table of contents
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?
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:
- Refer the JAVA_HOME to a JDK
- Maven on Eclipse : The correct configuration
- 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:
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:
- Go to System properties -> Advanced system settings -> Advanced -> environment variable and on the System variables section select the JAVA_HOME variable and click on Edit
- Fill the form with the following
Variable name: JAVA_HOME
Variable value: <ABSOLUTE_PATH_TO_JDK_HOME>
If you are using command line you can set the variable before running the build as following:
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:
- Open your Eclipse, click on Windows -> Preferences -> Java -> Installed JREs
- Verify that the checked JRE refers to a JDK : Select the checked JRE and click Edit… and change the path to the JDK home.
- Click OK.
The “No 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 :