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

In this post, we will learn different ways to solve error

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK.
This error may occur during the Maven build. Let's find out the solution below:

Read Also :  [Fixed] Java Was Started but Returned Exit Code=13 Error in Eclipse

Solution:

1. Using Maven in Eclipse Error

If you are running Maven from your IDE i.e. Eclipse then you must check that your IDE environment is using a JDK rather than a JRE. Below are the steps:

1.1 Open your Eclipse, then go to:
  Window -> Preferences -> Java -> Installed JREs

Verify if JDK is checked rather than JRE.
[Fixed] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK
if JRE is checked as shown in the above image then you need to add JDK by following the below step.

1.2 Go to
  Add -> Standard VM -> Next -> Directory 

browse the JDK path as shown in the below image.
[Fixed] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK

After configuring JDK, the Eclipse should look like below:
[Solved] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK

That's it, the above steps shall resolve the error in Eclipse.

2. Setting JAVA_HOME to JDK

If you are using Maven in command-line then Maven relies on the JAVA_HOME environment variable to use the right compiler.

Note: JAVA_HOME must refer to a JDK (Java Development Kit) rather than a JRE (Java Runtime Environment).

If JAVA_HOME is not set in your system. Then follow the below steps:

2.1 Go to
  System Properties -> Advanced system settings -> Advanced -> Environment Variables

then add JAVA_HOME to an environment variable. Please find the images below:

setting JAVA_HOME environment variable


JAVA_HOME system variable

3. Adding the configuration in pom.xml

You can add the following configuration in your maven-compiler plugin i.e. set fork to the true and full path to the Java compiler.

<build>
...
	<plugins>
	 ...
		<plugin>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.1</version>
		        <configuration>
		            <fork>true</fork>
                	    <executable>C:\Program Files\Java\jdk1.8.0_291\bin\javac.exe</executable>
		        </configuration>
		</plugin>
	</plugins>
</build>

4. Add the tools.jar

If all the above steps do not solve the error, then you can try this one also.

4.1 Open Eclipse, then go to
 Window -> Preferences -> Installed JREs -> Edit -> Add External Jars

Select tools.jar from java/JDKx.x/lib folder.
Click Finish.

That's all for today. Please mention in the comments in case you know any other way to solve no compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK error.

About The Author

Subham Mittal has worked in Oracle for 3 years.
Enjoyed this post? Never miss out on future posts by subscribing JavaHungry