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

1,521,061

Solution 1

  1. On your Eclipse IDE, go into Window > Preferences > Java > Installed JREs > and check your installed JREs. You should have an entry with a JDK there.
  2. Select the Execution Env as show below. Click OK
  3. Then Right-Click on your Project -> Maven -> Update Project

Additionally, you may have to change Maven JRE (see @jlars62 answer) which is as follows. Goto Run -> Run Configurations, selecting the Maven Build I was running (from the left panel). Then, I clicked the JRE tab and selected the option Workspace default JRE

enter image description here

Solution 2

  1. Set the JAVA_HOME environment variable to the JDK root folder - required if you run command line or maven (mvn).
    • (Search google for JAVA_HOME for more info)
  2. In project properties in section Java Compiler select required JDK - if you run directly from eclipse

Solution 3

For me, it is exactly what the maven of eclipse complains

enter image description here

So, I press Edit button and change path to the JDK Folder, then clean project and everything starts to work

Solution 4

For me, nothing worked until I made this change to my pom.xml:

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

Other Notes

I could see that m2e was executing in a JRE, not the JDK. Nothing I did changed this, including adding this to the eclipse.ini:

-vm
C:\Program Files\Java\jdk1.7.0_45\bin\javaw.exe

In the end I never got m2e to execute in a JDK, but setting the Java compiler explicitly (as above) did the trick.

Solution 5

In my case it was solved by doing this:

Go to your 'Runtime Configuration' and configure your JRE to an JDK.

Select the right JDK for your Runtime

Select default JRE

I copied answer just in case it is deleted for some reason, but the source is here

Share:
1,521,061
Sai prateek
Author by

Sai prateek

Ahaṁ Brahmāsmi (अहम् ब्रह्मास्मि) I'm infinite by nature, I'm Supreme power of universe, I'm the whole in myself. I'm a yogi with natural values and with power of integrated component of infinite universe. I breath, I live, I do karma. Here is my Linkedin profile.

Updated on July 08, 2022

Comments

  • Sai prateek
    Sai prateek almost 2 years

    I'm compiling a project in Eclipse using m2eclipse. I set the JDK path in Eclipse like this:

    Windows-->preferences-->installed jres--> jdk1.7.xx  path
    

    But this is showing an error

    [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] ------------------------------------------------------------------------
    [INFO] Total time: 1.424s
    [INFO] Finished at: Tue Oct 29 15:21:01 IST 2013
    [INFO] Final Memory: 5M/15M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-   plugin:3.1:compile (default-compile) on project TEST-WEB: Compilation failure
    [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    
  • Duncan Jones
    Duncan Jones over 10 years
    Why is step 1 required?
  • msangel
    msangel over 10 years
    @DuncanJones, first is required if you run command line or maven(google for this variable), second - if you run directly from eclipse,
  • Duncan Jones
    Duncan Jones over 10 years
    I would add that information to your answer. Otherwise it suggests both are necessary in all cases.
  • koppor
    koppor over 10 years
    Pay attention that the JAVA_HOME does not end with "bin", but points to the root of the JDK.
  • Rob
    Rob over 10 years
    Needed this for the release-plugin as it doesn't use the jre settings from eclipse (with external maven installation)...
  • diyoda_
    diyoda_ over 10 years
    @jaipster I tried to do this, but I could not find the jdk in the left panel, I only can see the jre7. Do you know why?
  • jaipster
    jaipster over 10 years
    It could possibly be either you have jdk7 not installed on your machine or it is not configured in eclipse. Can you confirm.
  • αƞjiβ
    αƞjiβ over 9 years
    I have same issue as @Diode. I do have both JDK and JRE installed in my machine. And path looks like JAVA_HOME=C:\Program Files\Java\jdk1.8.0_25. What do you mean by "not configured in eclipse"?
  • jlunavtgrad
    jlunavtgrad over 9 years
    @Diode I had the same problem. I went to "Installed JREs" and clicked "Add..." From there I browsed to C:\Program Files\Java\jdk1.7.0_XX and then I could select the jre as jaipster described.
  • Tom Fink
    Tom Fink about 9 years
    I'd rather suggest to add the JRE using the "Add" button then manipulating a JRE entry to become a JDK entry! And after adding the JDK click the checkbox beside the JDK entry. This should already solve the issue(s) described in this post.
  • Tom Fink
    Tom Fink about 9 years
    For me it was enough just to add the JDK to the list of "Installed JREs" (not the best naming...) and checking the check box beside the new JDK entry making it the default VM.
  • nsandersen
    nsandersen almost 9 years
    This appears to be necessary to check in addition to the selected answer above.
  • Joe.wang
    Joe.wang over 8 years
    It is weird . because as the title of dialog shows this should place the Installed JREs instead of jdk folder. But It really solved me problem. Thanks
  • Salsero69
    Salsero69 over 8 years
    That was it for me. Funny is that sometimes I get errors that the default JRE is erroneously pointing to a JDK.
  • Gonen I
    Gonen I about 8 years
    I like this solution better, as it does not make you change the default java version for other projects.
  • Abhijit Chakra
    Abhijit Chakra about 8 years
    It's weired the title is Installed JREs but path is JDK but anyway it works thanks
  • Nyerguds
    Nyerguds almost 8 years
    Looks like updating my Java made it switch to the new JRE, not caring at all that there was no JDK attached to it. Stupid Eclipse...
  • Aritz
    Aritz almost 8 years
    This solution should be implemented as a last resort, since the project itself is modified to be coupled to your current dev machine.
  • The Mitra Boy
    The Mitra Boy over 7 years
    I clicked the "Search" button in the "Installed JREs" menu. Eclipse searched one the drives I pointed it to and came out with all the installed JREs and JDKs.
  • Anthony De Souza
    Anthony De Souza over 7 years
    I refactored/renamed my project and immediately had this problem. This fix resolved it. - I'm running Eclipse IDE: Version: Mars.2 Release (4.5.2)
  • In-young Choung
    In-young Choung over 7 years
    Thanks for sharing the JDK path. It seemed as though people could choose another option to click JDK when I only had JRE displayed from the beginning. I added JDK from the path you had provided.
  • Namrata Choudhary
    Namrata Choudhary about 7 years
    I have tried all above option mentioned by @ishu, but still getting org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project hibernateTest1: Compilation failure, then I tried your solution , but no change in error... Please help me.
  • Antony Fuentes
    Antony Fuentes almost 7 years
    @ksnortum thanks! this is the only thing that made it work for me.
  • logicbloke
    logicbloke almost 7 years
    What about us linux folks here?
  • ksnortum
    ksnortum almost 7 years
    I suspect it's pretty much the same, except the executable would be /path/to/java/bin/javac. Maybe try 'which java` to find your Java path.
  • user1084561
    user1084561 over 6 years
    For step 1 I chose my JDK instead of the JRE and set it as default. That did the trick for me.
  • Alekya
    Alekya almost 6 years
    Add <build> <sourceDirectory>flockWebclient</sourceDirectory> <resources> <resource> <directory>resources</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> in your pom.xml
  • Noumenon
    Noumenon over 5 years
    Update project was not enough for me. I had to clean.
  • leftbit
    leftbit over 5 years
    It's a good idea to remove the JRE after adding the JDK. Sometimes Eclipse keeps using the JRE regardless - no idea why this is the case. Making the JDK the only available option helps. :)
  • Dame Lyngdoh
    Dame Lyngdoh about 5 years
    This is a much better approach than changing the build path/run configuration settings in Eclipse for developers who are not using the IDE but using the command line tool of maven
  • Atul
    Atul about 5 years
    This worked for me. If JDK is not displayed in Alternate JRE dropdown, so you need to Add Installed JRE(Navigate to the folder where JDK is installed) and select the JDK folder.
  • BullyWiiPlaza
    BullyWiiPlaza almost 5 years
    This did the trick :) I forgot to define the JAVA_HOME variable when setting up the mvn command line application
  • Petro
    Petro over 4 years
    You the real hero!
  • Nagarajan S R
    Nagarajan S R over 4 years
    Check if JAVA_HOME is also set to avoid such issue
  • Amr Afifi
    Amr Afifi over 4 years
    This was my problem, thanks for your answer it got solved.
  • onlyme
    onlyme over 4 years
    Just don't confuse between jre and jdk. You have to add jdk installation path not jre
  • Admin
    Admin about 4 years
    Yeap thats what I just did, cause I'm using visual studio code, so using terminal Thanks
  • asifaftab87
    asifaftab87 about 4 years
    worked for me, I want to do maven clean install compile
  • okorng
    okorng almost 4 years
    For me, I verified these settings were correct as suggested, and cleaned the project, but it still failed. Finally I closed and reopened Eclipse and then it succeeded. So, there was something stuck about Eclipse that wasn't fixed until I restarted Eclipse.
  • Jlearner
    Jlearner almost 4 years
    While setting JAVA_HOME use Progra~1 instead of Program files since it has space in between e.g. C:\Progra~1\Java\jdk1.8.0_251
  • Minh Kha
    Minh Kha over 3 years
    The important things for those who run from mvn command, is need to set JAVA_HOME and point to JDK directory. Thanks for this
  • Raihanul Alam Hridoy
    Raihanul Alam Hridoy over 3 years
    BUILD SUCCESSFUL. Thanks
  • gekkedev
    gekkedev over 3 years
    I would like to highlight that my JAVA_HOME path was already pointing to the bin folder and after trying both subfolders for either JRE and JDK I figured the path in your example actually is not the bin folder, which felt a bit counter-intuitive.