Thursday, August 4, 2022

How to fix "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK" in Eclipse & Maven?

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 Maven 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 files. 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 the 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.

Btw, if you are just starting with Maven, I suggest you first go through a comprehensive Maven course like to learn some fundamentals. If you need recommendations, check these Maven online courses for Java programmers. It will not only help you to build and deploy your Java and Spring Boot projects using Maven but also learn Maven itself in depth.


Tools and Environment

  • JDK 1.8
  • Eclipse Kepler
  • M2Eclipse 
  • Apache Maven 3.0.3

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

Here is the stack trace :

[ERROR] COMPILATION ERROR : 
[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] BUILD FAILURE
[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 the below steps to configure JDK in Eclipse and solve this error:

1. Check if you have JDK configured in Eclipse, you can do this 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 it in Eclipse by clicking the add button on the 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 this 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 the following 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 an issue then you can let me know by dropping a comment here, or you can also refer to these Apache Maven courses to understand how to set up Maven for Eclipse in the right way and how to use Maven effectively with 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 the 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.

Other Java Debugging and Troubleshooting Guide You May Like
  • How to solve java.lang.ClassNotFoundException in Java [guide]
  • How to solve java.lang.UnsatisfiedLinkError: no ocijdbc11 in Java [solution]
  • How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver in Java? [solution]
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
  • How to fix java.lang.ClassNotFoundException: org.postgresql.Driver error in Java? [solution]
  • How to solve java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver [solution]
  • java.net.SocketException: Failed to read from SocketChannel: Connection reset by peer [fix]
  • Exception in thread "main" java.lang.ExceptionInInitializerError in Java Program [fix]
  • java.net.SocketException: Too many files open java.io.IOException [solution]
  • 2 ways to solve Unsupported major.minor version 61.0 error in Java [solutions]
  • java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver [solution
  • Fixing Unsupported major.minor version 53.0 Error in Java [solution]
  • java.net.BindException: Cannot assign requested address: JVM_Bind [fix]
  • java.io.IOException: Map failed and java.lang.OutOfMemoryError: Map failed  [fix]
  • org.hibernate.MappingException: Unknown entity Exception in Java [solution]
  • java.lang.ClassNotFoundException:org.Springframework.Web.Context.ContextLoaderListener [solution]
  • Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 [solution]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Java MySQL? [solution]
Thanks for reading this Java debugging tutorial so far. If you find my solution useful, please share this article with your friends and colleagues. 

2 comments :

Java_Monk said...

Still i'm facing the issue
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ms-Server: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ms-Server: Compilation failure
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Please refer any other solution

javin paul said...

Hello @Java Monk, Maven uses JAVA_HOME environment variable, check what is the value of this variable in your system, you can just go to command prompt and type
$ echo %JAVA_HOME% on Windows or $echo $JAVA_HOME on Linux. I think it's pointing to JRE which doesn't have Java compiler "javac" and that's why Maven is not able to compile JAva course code and giving this error.

Post a Comment