Maven Eclipse Error - "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK"

If you are like many Java developer who uses Maven and Eclipse to build Java project using M2Eclipse plugin, you might have seen this error before. I ran into it recently when I ran the Maven Install command for one of the Java projects, configured as Maen project,  only to realize that Maven builds failed after throwing this error. The main reason for this error is that Maven is not able to find javac (the Java compiler) which is required to compile Java source file. If you remember, the javac command comes in the bin directory of JDK, hence, you need a JDK installation in your local machine to compile Java project. You also need to have that configured in Eclipse as Installed JRE. Most likely, you have only installed and set up JRE and not JDK, at least that was the reason it throws "No compiler is provided in this environment" in my machine.

Tools and Environment
  • JDK 1.8
  • Eclipse Kepler
  • M2Eclipse 
  • Apache Maven 3.0.3

I had a Java project configured as Maven project and the following error came when I run the Maven install command

Here is the stack trace :

[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------

Later I checked the Installed JRE in Eclipse there was no JDK there. The solution was to configure the JDK 8 installed on my machine.

How to solve Maven Eclipse Error of no JRE or JDK found

You can follow below steps to configure JDK in Eclipse and solve this error:

1) Check if you have JDK configured in Eclipse, you can do  by  going to Window → Preferences → Java → Installed JRE, as shown in the following diagram:

How to check if JRE or JDK installed in Eclipse - Maven Error

2) If there is no JDK installed then download the JDK and configure in Eclipse by clicking the add button on same screen as shown below:

How to install and attach JRE to Eclipse

3) Change the default JRE of the project to point to JDK. You can do by right click on the project, then go to Java Build path and then click add Library method and choose JRE library as shown below:

How to change default JRE of a Java project in Eclipse

I hope following below steps will help you to solve the Maven build related error you are getting while compiling your Maven Java project in Eclipse. If you still face issue then you can let me know by dropping a comment here, or you can also refer a good book like Maven for Eclipse to understand how to setup Maven for Eclipse in the right way and how to use Maven effectively with Eclipse.

How to configure Maven in Eclipse

That's all about how to solve "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK" error while using Maven in Eclipse via M2Eclipse plugin. The error message is very accurate in this case as it happened I only had JRE configured in Eclipse. I have configured the installed JDK in Eclipse and set that as my project default JRE and boom, I am managed to build the project using Maven install.

No comments :

Post a Comment