101

My environment is Windows 7 64bit with Eclipse [Kepler SR1] and Maven. I have to run a Maven install to deploy a code change, but this error is showing in the console:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project mrpapp: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

but I definitely am running a JDK and not a JRE. I double-checked my $JAVA_HOME (C:\Program Files (x86)\Java\jdk1.7.0_60) and it does have a javac.exe in its bin directory.

ErikE
  • 48,881
  • 23
  • 151
  • 196
Ken L
  • 1,145
  • 2
  • 8
  • 6
  • What does it say in Eclipse under when you click Window->Preferences->Java->Compiler? If that's not it you might also check your eclipse.ini file to make sure it's not pointing to a java jre install. – Robert Beltran Jan 13 '14 at 18:59
  • 5
    Assuming it is the Eclipse build that is failing, have you tried running a Maven command (e.g. `mvn install`) directly from the command line? One of these two questions may also help: http://stackoverflow.com/questions/19655184/no-compiler-is-provided-in-this-environment-perhaps-you-are-running-on-a-jre-ra and http://stackoverflow.com/questions/15220392/maven-package-compilation-error – andersschuller Jan 13 '14 at 19:00
  • 1
    open a command window and type `javac -v` does it work? – Henry Jan 13 '14 at 19:04
  • Discovering which java is actually running your build is trickier than it should be. Try running `mvn help:system` and verify the environment settings **and System Properties** match what you expected. – Gus Jan 13 '14 at 19:04
  • 2
    @andersschuller has a really good point -- is this failing from the command line, or from eclipse? – Gus Jan 13 '14 at 19:06
  • The problem was occurring within Eclipse itself. When I followed Robert's suggestion, I discovered there was a second path directly under my default one, and it was pointing to a JRE. I simply deleted that entry and after that, I was finally able to do a Maven Install without errors. Problem solved. – Ken L Jan 13 '14 at 19:53
  • In my case it was a wrong installation of the jdk See http://stackoverflow.com/questions/34559379/java-1-8-65-javac-is-missing –  Feb 18 '16 at 06:40

27 Answers27

185

Go to Window → Preferences → Java → Installed JREs.

And see if there is an entry pointing to your JDK path, and if not, click on Edit button and put the path you configured your JAVA_HOME environment.

Rajat
  • 314
  • 4
  • 15
Jorge Campos
  • 22,647
  • 7
  • 56
  • 87
  • 4
    Thank you both! I went to Window->Preferences->Java->InstalledJREs and saw that a different path was listed below my default. I removed that one and, when I attempted the Maven Install, it ran without errors. Problem solved! – Ken L Jan 13 '14 at 19:26
  • 2
    Worked for me. Even there was jre8 location given (of Program Files(x86)). I have changed it to jre7..worked. – Anil Bhaskar Aug 19 '15 at 17:38
  • it works for me, but it's really weird..! Anyone found another possibile fix? – Dwhitz Feb 07 '17 at 08:56
  • @Dhn What do you mean it is weird? If you are talking about the error itself it is not weird at all. One of the goals of Maven is to compile java code, therefore it needs the JDK instead of the JRE. – Jorge Campos Feb 07 '17 at 11:38
  • It's weird because eclipse want a jdk as jre.. and i've also many other errors because i've imported the same project with intellij and immediatly it shows me an error like "invalid jre" . Moreover many other conf and libs aren't recognised for the wrong jre.. – Dwhitz Feb 07 '17 at 12:43
  • In my case, it was also important to eliminate the installed JRE from the list. Maven is using its own methodology for selection from the list and it is not very smart in that regard. – Jason K. Jul 24 '20 at 18:33
  • Hi @JasonK. It is not maven doing that. That's the Eclipse Maven Plugin, and if it was reading the JRE listed there even after you added the JDK means that either you did not select the JDK or a project configuration was overriding your IDE configuration. – Jorge Campos Jul 24 '20 at 23:08
  • @JorgeCampos I should have been more specific, but since we are talking about Eclipse/Maven, my intent was to reference the plugin. That said, I did have the JDK selected and the project does not override the IDE configuration. Both are good, obvious points to ensure, but only by eliminating the JRE from the list was I able to eliminate the error. Even when I added the JRE back after eliminating the error, the error would return. – Jason K. Jul 24 '20 at 23:51
  • @JasonK. thanks for clarifying... must be some bug on your eclipse version then... I'm currently using Eclipse 2019-06 and I have both jre and jdk there working fine :) – Jorge Campos Jul 25 '20 at 01:09
33

Screen_shot Add 'tools.jar' to installed JRE.

  1. Eclipse -> window -> preference.
  2. Select installed JREs -> Edit
  3. Add External Jars
  4. select tools.jar from java/JDKx.x/lib folder.
  5. Click Finish
Jobin
  • 5,610
  • 5
  • 38
  • 53
sibabrata
  • 331
  • 3
  • 3
18

Go into Window > Preferences > Java > Installed JREs > and check your installed JREs. You should have an entry with a JDK there.

https://cduu.wordpress.com/2013/03/08/maven-eclipse-compiler-error-no-compiler-is-provided-in-this-environment/

Gubatron
  • 6,222
  • 5
  • 35
  • 37
17

I tried all the things; the one that worked for me is:

  1. Right click on Eclipse project and navigate to properties.
  2. Click on Java Build Path and go to the Libraries tab.
  3. Check which version of Java is added there; is it JRE or JDK?
  4. If you are using Maven project and want to build a solution.
  5. Select the JRE added their and click remove.
  6. Click Add external class folder and add the JDK install by selecting from the system.
  7. Click Apply and OK.
  8. Restart Eclipse.
  9. Build succeeded.
df778899
  • 10,703
  • 1
  • 24
  • 36
Archana Prasad
  • 171
  • 1
  • 2
  • Right ! it worked for me, after i configured Eclipse in preferences with JDK and re build the project, this problem still occures. And The solution above worked. – Badr DRAIFI Aug 08 '15 at 15:09
11

Add this configurations in pom.xml

<project ...>
    ...
    <build>
        ...
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <fork>true</fork>
                    <executable>C:\Program Files\Java\jdk1.7.0_79\bin\javac</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>
AnuradhaS
  • 341
  • 2
  • 10
10

This worked for me. 1. Click on Window-> Preferences -> Installed JRE. 2. Check if you reference is for JDK as shown in the image below. enter image description here

If not, Click on Add-> Standard VM -> Give the JDK path by selecting the directory and click on finish as shown in the image enter image description here

  1. Last step, click on Installed JREs -> Execution Environments -> select your JDE as shown in the image below enter image description here

  2. Maven -> Clean

S S
  • 313
  • 4
  • 12
9

When I was runing mvn compile, I was getting below error in console:

[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1087 source files to C:\Code\DevVNextComplete\Development_vNext\Source\JARS\target\classes
[INFO] -------------------------------------------------------------
[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

[Resolution]

I had added, the JAVA_HOME variable in my environment variables and then it worked.

enter image description here

Vaibhav Sharma
  • 1,573
  • 2
  • 19
  • 35
4

I also faced similar error when I was working with Jdk1.8_92. For me, I found tools.jar was missing in my jdk folder. Since I was running in console, I couldn't try the options of eclipse suggested by others..

I installed jdk-8u92-windows-x64. After I tried all options, I observed that tools.jar was missing in jdk1.8.0_92/lib folder. I copied tools.jar from my older version of java. Then It was able to compile.

Manish
  • 81
  • 1
  • 7
3

I was getting the same error when trying to execute a maven build within Eclipse in a newly installed Eclipse Neon (for JEE devs) installation, on Windows 10 with JDK 8 and JRE 8 installed.

I had tried specifying tools.jar as an external lib, as well as setting the jdk as the -vm in eclipse. Neither of these things worked.

Selecting the JDK as the default execution env as mentioned above did the trick..

  1. Eclipse->window->preference->java->Installed JREs->Execution Environments.
  2. Select JavaSE-1.8
  3. Check JDK1.8 in "Compatible JREs".

The text above the compatible JREs listbox in step 3 says "a default JRE can be specified by checking it"

Note: I also have the maven compiler plugin explicitly listing 1.8 in the pom

    <plugin>  
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
Tim
  • 31
  • 1
3

Follow : Windows --> Preferences --> Java ---> Installed JREs

SampleImage

Click on "Search.."

Navigate to C drive ---> Program files

Sample Image 2

Eclipse will find all the jre's and jdk's --> select one of the jdk and select Apply

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Mayur Chavan
  • 833
  • 8
  • 14
2

Please check if you have the following entries in the element of your pom.xml especially the jdk.version because switching to an installed jre did not fix me the similar error.

<properties>
    <jdk.version>1.7</jdk.version>
    <spring.version>4.1.1.RELEASE</spring.version>
    <jstl.version>1.2</jstl.version>
    <junit.version>4.11</junit.version>
</properties>
Balaji
  • 125
  • 9
2

if someone is running Eclipse in Ubuntu and have this problem I have found the answer by following these steps:

  1. Eclipse->window->preference.
  2. Select installed JREs->Add
  3. Select standardVM.
  4. JRE home: press [Directory..] button.
  5. Choose your java (my problem was my eclipse was running with java8 and my VM were with java7), in my case java8 was installed in usr/local/jvm/java-8-oracle.
  6. Press finish.
  7. Then press installed JRES arrow so you can see the other options.
  8. Go to Execution Environment.
  9. Select JavaSE-1.6 on left and in the right (the compatible JRE) you have to choose the Java you have just installed( in my case java-8-oracle). you have to do this steps with JavaSE1.8.
  10. Click OK and restart Eclipse.
ManoDestra
  • 6,325
  • 6
  • 26
  • 50
2

Installed JRE In my case I solved the problem by removing duplicates of names, I kept only one with the name: jdk.1.8.0_101

1

In my case, I had created a run configuration and whenever I tried to run it, the error would be displayed. After searching on some websites, I edited the run configuration and under JRE tab, selected the runtime JRE as 'workspace default JRE' which I had already configured to point to my local Java JDK installation (ex. C:\Program Files (x86)\Java\jdk1.8.0_51). This solved my issue. Maybe it helps someone out there.

chepaiytrath
  • 678
  • 1
  • 9
  • 20
1

was getting the same problem, pointed java to bin folder in eclipse using: windows > preferences > java > installed JREs > remove any existing JRE and point it to your java bin folder (mainly under C:\Program Files\Java\jdk1.8.x_xx).

then run maven install it should work.

Rajan Chauhan
  • 461
  • 2
  • 7
  • 18
1

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

mvn –version

Verify that JAVA_HOME refers to a JDK home and not a JRE

On Windows:

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:

On Unix:

export JAVA_HOME=<ABSOLUTE_PATH_TO_JDK>

see this link

TopekoX
  • 319
  • 2
  • 5
0
  1. Uninstall older Java(JDK/JRE) from the system( Keep one (latest) java version), Also remove if any old java jre/jdk entries in environment variables PATH/CLASSPATH
  2. Eclipse->Window->Preferences->Installed JREs->Add/Edit JDK from the latest installation
  3. Eclipse->Window->Preferences->Installed JREs->Execution Environment->Select the desired java version on left and click the check box on right
  4. If you are using maven include the following tag in pom.xml (update versions as needed) inside plugins tag.

    <plugin>  
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    
  5. Right click on eclipse project Maven - > Update Project
Bruce
  • 793
  • 8
  • 17
0

For me (on windows 10), I was getting the error "No compiler is provided in this environment" at the Windows command prompt when I ran mvn install. The fix was changing the JAVA_HOME environment variable to point to my jdk (C:\Program Files\Java\jdk1.8.0_101); previously it had pointed to the jre.

And to get Eclipse to use the new jdk, I edited eclipse.ini in my eclipse distribution and changed the line for -vm to C:\Program Files\Java\jdk1.8.0_101\bin.

Don Smith
  • 473
  • 4
  • 10
0

check java version in pom.xml and jre version in Eclipse->Window->Preferences->Installed JREs. In my case pom.xml has different version(it had 1.8 while eclipse using 1.7). Fixing the version in pom.xml to 1.7 worked.

0

if you are working outside of eclipse in the command window
make sure you have the right JAVA_HOME and that that directory contains the compiler by entering the following command in the command window:

dir %JAVA_HOME%\bin\javac.*
inor
  • 2,781
  • 2
  • 32
  • 42
0

1.Go to Windows-->Preferences-->Java-->Installed JREs-->Execution Environments

2.select the java version you are using currently in the "Execution Environments" box. So that in the "Compatible JREs" box, you are able to see as "jre1.8.0_102[perfect match]"(if your java version is 1.8). Then try to build using maven.

0

Maven requires JDK to compile. In Eclipse you need to CHANGE/ REPLACE your JRE to the JDK path that your JAVA_HOME points to. Navigate to Window > Preferences > Java > Installed JREs.

Make sure that the maven-compiler-plugin in you pom.xml has the source and target of the java version in your JAVA_HOME

http://learn-automation.com/maven-no-compiler-is-provided-in-this-environment-selenium/

rnyunja
  • 219
  • 3
  • 4
0

Make sure you have %JAVA_HOME% set by typing echo %JAVA_HOME% in Command Prompt. If you don't have that set, then you need to go add your Java path to Window's Environmental Variables.

Gene
  • 10,819
  • 1
  • 66
  • 58
0

I resolved this issue by providing JAVA_HOME in my enviroment variables and restarted intellij

MiniSu
  • 566
  • 1
  • 6
  • 22
0

you can follow any of one from given below.

  1. Project--properties--java build path--jre system library--edit--add library path as JDK
  2. Window preference--java--installed JRE--JRE system library--add library and provide path to JDK folder
  3. You will have to instruct eclipse to use JDK as build/compile source in some ways if it's configured to point to jre instead For default compiler
AmolRavan
  • 33
  • 6
0

If none of the above helped still You are facing the same issue means you may have misconfigurations in your Custom Run/Debug Configurations.

In My case I am using a Custom maven run configuration. There the JRE is pointed earlier. Once I changed it to JRK it worked as expected.
enter image description here

RAJESH KUMAR ARUMUGAM
  • 1,560
  • 21
  • 35
-1

I had a problem with Eclipse Neon where the workspace default did not actually change even though I added the correct location under Preferences->Java->Installed JREs. This was in a new workspace I created to work on a code branch; it was originally set to the JRE location rather than the JDK. Yet even after changing the preferences, I could build with the command line, yet building in Eclipse produced the no compiler error. Please see

Maven Package Compilation Error

for my answer on which Eclipse configuration file(s) had to be manually edited to make Eclipse recognize the correct workspace default. I still have no idea why the preferences setting did not carry through to the new workspace's configuration.