694

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?
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Sai prateek
  • 10,642
  • 8
  • 39
  • 60
  • 1
    how are you starting the compile? Commandline? Eclipse tool? – Joeri Hendrickx Oct 29 '13 at 10:15
  • from eclipse tool Run configuration--> Goals: clean install – Sai prateek Oct 29 '13 at 10:21
  • possible duplicate of [Maven Package Compilation Error](http://stackoverflow.com/questions/15220392/maven-package-compilation-error) – mlt Aug 17 '15 at 18:56
  • 7
    Hey, This error is coming because Maven is trying to get JDK but in eclipse it is pointing to JRE. You can change path to JDK and it will work. Check below post which will help you http://learn-automation.com/maven-no-compiler-is-provided-in-this-environment-selenium/ – Mukesh otwani Jul 02 '16 at 09:49
  • i'm posting link this so that someone in future may get benefited as i did. http://stackoverflow.com/a/33873838/4525120 – divine Feb 25 '17 at 00:21
  • Advanced users for whom this is a frequent problem, may include the standalone eclipse compiler in their pom, instead of relying on javac. – Thorbjørn Ravn Andersen Mar 18 '19 at 08:49
  • I have this issue every time I run as mvn install in eclipse. the workaround I have found is to clean the project one time that changes the environment back to JDK than run as mvn install. Works For me every time. – Somnath Singh May 26 '20 at 14:52

33 Answers33

1065
  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

jaipster
  • 11,767
  • 2
  • 19
  • 24
  • 18
    @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? – diyoda_ Feb 26 '14 at 03:50
  • 5
    It could possibly be either you have jdk7 not installed on your machine or it is not configured in eclipse. Can you confirm. – jaipster Feb 26 '14 at 04:28
  • 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"? – αƞjiβ Jan 11 '15 at 21:30
  • 61
    @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. – jlunavtgrad Jan 27 '15 at 21:03
  • 8
    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. – Tom Fink Apr 01 '15 at 11:19
  • 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... – Nyerguds Aug 02 '16 at 11:58
  • 7
    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. – The Mitra Boy Nov 26 '16 at 22:58
  • 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) – Anthony De Souza Jan 18 '17 at 17:55
  • For step 1 I chose my JDK instead of the JRE and set it as default. That did the trick for me. – user1084561 Jan 22 '18 at 21:22
  • Update project was not enough for me. I had to clean. – Noumenon Sep 27 '18 at 22:09
  • You the real hero! – Petro Oct 18 '19 at 15:52
  • Check if JAVA_HOME is also set to avoid such issue – Nagarajan S R Nov 27 '19 at 08:29
  • Just don't confuse between jre and jdk. You have to add jdk installation path not jre – onlyme Mar 22 '20 at 22:45
  • 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. – okorng Aug 21 '20 at 00:34
148

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

Thai Tran
  • 9,353
  • 6
  • 39
  • 59
  • 4
    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 Apr 01 '15 at 11:18
  • 3
    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 – Joe.wang Jan 13 '16 at 02:40
  • It's weired the title is Installed JREs but path is JDK but anyway it works thanks – Abhijit Chakra May 12 '16 at 07:48
  • 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. :) – leftbit Oct 24 '18 at 11:02
143
  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
TT--
  • 2,186
  • 21
  • 41
msangel
  • 8,829
  • 3
  • 43
  • 64
  • Why is step 1 required? – Duncan Jones Oct 29 '13 at 10:33
  • 2
    @DuncanJones, first is required if you run command line or maven(google for this variable), second - if you run directly from eclipse, – msangel Oct 29 '13 at 15:11
  • 1
    I would add that information to your answer. Otherwise it suggests both are necessary in all cases. – Duncan Jones Oct 29 '13 at 15:21
  • 14
    Pay attention that the JAVA_HOME does *not* end with "bin", but points to the *root* of the JDK. – koppor Dec 22 '13 at 15:44
  • Needed this for the release-plugin as it doesn't use the jre settings from eclipse (with external maven installation)... – Rob Feb 14 '14 at 14:37
  • 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 – Dame Lyngdoh May 23 '19 at 16:09
  • This did the trick :) I forgot to define the `JAVA_HOME` variable when setting up the `mvn` command line application – BullyWiiPlaza Sep 20 '19 at 10:39
  • Yeap thats what I just did, cause I'm using visual studio code, so using terminal Thanks – AbdessamadEL May 04 '20 at 22:18
  • 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` – Jlearner Aug 23 '20 at 06:04
138

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.

ksnortum
  • 2,558
  • 4
  • 23
  • 35
47

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

Community
  • 1
  • 1
Eduardo Dennis
  • 12,511
  • 11
  • 72
  • 102
  • 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. – Atul May 29 '19 at 06:07
  • This was my problem, thanks for your answer it got solved. – Amr Afifi Feb 05 '20 at 13:16
40

I was getting this error when trying to do a maven build from within eclipse.

For me, the answer was going to 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

jlars62
  • 6,366
  • 7
  • 34
  • 56
35

Go to windows -> Preferences -> Java -> Installed JREs

may be jre is already added enter image description here

click on Add -> Standard VM -> Next -> Directory

and browse for the JDK in my case path was C:\Program Files\Java\jdk1.8.0_111

then Click on finish.

you will see window like thisenter image description here

select JDK -> Apply -> Ok

And You are done.

Community
  • 1
  • 1
GauRang Omar
  • 761
  • 7
  • 17
  • 1
    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. – In-young Choung Feb 12 '17 at 21:59
21

I got same issue and i just add JAVA_HOME to environment variables.

env var

  • If you are using eclipse, just refer https://stackoverflow.com/a/21279068/6097074
  • If you are using intellij, just after adding JAVA_HOME open command prompt from project directory and run mvn clean install(don't use intellij terminal).
ankit
  • 1,919
  • 19
  • 39
  • 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. – gekkedev Mar 22 '21 at 12:42
14

I tried all of the above, however, still getting the same error message.

In my case an actual JRE was incorrectly used as JRE System Library in the project-specific build path which was obviously overriding all those other settings discussed here.

If that is so in your case try the following:

  1. Open the project-specific libraries of the Java Build Path: Right-click "Project > Build Path > Configure Build Path..." and select "Libraries" tab.
  2. Select the "JRE System Library" entry and hit "Remove".
  3. Hit "Add Library...".
  4. A wizard pops up. Select "JRE System Library" and hit "Next >".
  5. Now select the correct JDK (in my case "Workspace default JRE", which I configured using a JDK).
  6. Close wizard by hitting "Finish".
  7. Close "Properties" dialog by hitting "OK".
Sir Hackalot
  • 371
  • 4
  • 16
  • 1
    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. – Namrata Choudhary May 31 '17 at 06:40
  • Add ` flockWebclient resources **/*.java maven-compiler-plugin 3.5.1 1.8 1.8 ` in your pom.xml – Alekya Aug 02 '18 at 11:51
11

An alternative if jaipster's answer does not work is to go to:
Window > Preferences > Java > Installed JREs

Then to edit the jre so that it points to the jdk and not the jre (the jre home filed in the jre package editor)

That worked for me.

brunoais
  • 4,743
  • 7
  • 33
  • 55
11

If you are running the Maven command from cmd, make sure you set the jdk path before running the command. In my case, I have created a .bat file containing the following:

set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60
start cmd.exe /k "cd c:\aem_proj\sis\aau"
k0pernikus
  • 41,137
  • 49
  • 170
  • 286
Mahder
  • 399
  • 3
  • 9
11

I faced the same issue while trying to build a jar file of my project application using mvn clean install, though the application was working fine while running from Eclipse.

The issue was, indeed too naive, that I had not set the JAVA_HOME environment variable. All I had to do is set JAVA_HOME environment variable to JDK directory, make sure it is not till "\bin" and without semi-colon ";".

enter image description here

How I understood it is as:

The application worked fine in Eclipse as JRE System Library was referring to JRE inside the JDK folder instead of external JRE folder without JDK. [As explained very well in other answers]

This configuration does not apply to maven command that we run on command prompt. It will still look for JAVA_HOME variable to access the JRE System library and when it is not found it refers to external JRE folder without JDK.

Dhaval Simaria
  • 1,366
  • 2
  • 22
  • 31
  • 1
    The important things for those who run from mvn command, is need to set JAVA_HOME and point to JDK directory. Thanks for this – Minh Kha Jan 29 '21 at 06:33
9

My answer pertains to the Eclipse in Windows environment.

I went to Preferences --> Java --> Installed JREs I did NOT see the JDK in here. I only saw the JRE here. So I added the JDK and then unchecked the JRE. Then checked JDK. Then I ran the POM file using Run Configurations. Choose the tab JRE and select the option "Workspace Default..." Here are the images

enter image description here

enter image description here

7

There are several options to specify.

Steps: Right on project in project explorer Go to Run-> Run Configuration -> Click Maven Build -> Click on your build config/or create a new config. You will see the window as the given snapshot below, click on JRE tab there.

You see you have 3 options 1) Workspace Default JRE 2)Execution Environment 3)Alternate JRE enter image description here 1) Workspace Default JRE is set from 'Window' menu on the top -> Preferences -> Java -> Installed JREs -Here you can add your jdk enter image description here 2) Execution Environment jdk can be set in pom.xml as mentioned by @ksnortum

<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>

3) Alternate JRE can be used to select a jdk from your directory

manntsheth
  • 420
  • 5
  • 8
7

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

Solution

Please set the Environment variable like below to solve the issue

Variable name : JAVA_HOME

Variable Value : C:\Program Files\Java\jdk1.8.0_202

Variable name : M2_HOME

Variable Value : C:\Program Files\apache-maven-3.6.0

Moreover, Add Java and maven path in "System Variables" like below:

  1. C:\Program Files\Java\jdk1.8.0_202\bin

  2. C:\Program Files\apache-maven-3.6.0\bin

Navdeep Ghotra
  • 161
  • 2
  • 3
6

Though the question is about the error with Eclipse setup but thought an answer of fixing this error with IntelliJ and Windows 10 setup may also be helpful here.

1. Go to File --> Settings --> Build, Execution, Deployment --> Build Tools --> Maven --> Importing

2. Set JDK for Importer as shown below to JAVA_HOME

enter image description here

Also JAVA_HOME should be set to JDK path at Environment Variables --> System variables and also add %JAVA_HOME%\bin to Path System variables

Nafeez Quraishi
  • 3,494
  • 2
  • 19
  • 29
5

For me the JRE was in the PATH environment variable before the JDK path

  1. C:\ProgramData\Oracle\Java\javapath
  2. C:\env\jdk1.8.0_151\bin

So I removed 1. Probably swapping them would fix it too.

Florin D
  • 1,101
  • 11
  • 13
3

There is another possible answer to this question, and I may be the only person foolish enough to have stumbled upon this, but I think it's worth adding, since none of the other answers applied as I already had those settings correct.

When you install a JDK, the installer asks you where you want to install the files. By default, on Windows, this is something like C:\Program Files\Java\jdk1.8.0_74 (or whatever version you are installing).

It then asks you for a directory to install the JRE to, which by default is something like C:\Program Files\Java\jre1.8.0_74.

Note that one is jdk1.8.0_74 and the other is jre1.8.0_74

I was rushing things, and thinking the installer was asking me the same question twice, set both my JDK and JRE install locations to D:\devtools\jdk\jdk1.8.0_74, resulting in the installer overwriting the JDK with the JRE. This resulted in (among other things) a missing javac.exe in my JDK bin, and the same error the OP reported here in all my maven builds.

Sam
  • 162
  • 7
3

I got a solution.

The most common solution for this problem is to change jdk location as my Installed JREs instead of the JRE location but that did not solve my problem this one time.

So I did the below to solve the problem. Expand the Installed JREs tab and you will find a Execution environments tab.

Click on your favourite execution environment. In my case it was JAVASE-1.8. There it shows 2 options. JDK and JRE. Select JDK there and the problem is solved.

enter image description here

Vero J
  • 231
  • 2
  • 6
3

I tried most of the answers without success. What worked for me was (after following https://stackoverflow.com/a/21279068/2408893):

  • right click on project -> Properties
  • select Java Build Path
  • select the JRE System Library
  • click edit
  • In execution environment select a jdk

enter image description here

  • click Finish
  • build and run
2

I just wasted 3 hours with this problem until I managed to make it work. I had this error in the Eclipse Terminal when issuing a mvn compile command:

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

So I read here that I have to make a new system variable called JAVA_HOME and make it point towards the jdk installation folder. However this generated another error:

Source option 1.5 is no longer supported. Use 1.6 or later

Couldn't find a fix for this one so...

So the fix to make it all go away is install Java SE Development Kit 8! I was using 9 thinking that if it's the latest it must be better...

Anyway...

  1. Uninstall all java versions from your computer
  2. Install JDK8 from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

  3. Then define the JAVA_HOME system environmental value - tutorial here: https://docs.oracle.com/cd/E19509-01/820-3208/inst_cli_jdk_javahome_t/

  4. Restart Eclipse and enjoy! (at least that's what I did)

Hoping this spares some poor wanderer of some trouble.

JustNatural
  • 91
  • 3
  • 12
2

In my case I had system variable path has "C:\ProgramData\Oracle\Java\javapath" location.

In "C:\ProgramData\Oracle\Java\javapath" location java, javaw only there. So I am getting the same error.

Once I removed all files in "C:\ProgramData\Oracle\Java\javapath" folder my error got resolved.

Raja
  • 71
  • 1
  • 6
1

Try this.

<build>
...
    <plugins>
    ...
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <fork>true</fork>
                <executable> path to jdk \bin\javac.exe</executable>
            </configuration>
        </plugin>
    </plugins>
</build>
Draken
  • 3,049
  • 13
  • 32
  • 49
Wagh
  • 11
  • 2
1

i faced the same issue, the mistake i made was i added jre path only in the path var,not jdk path .When jdk path was added to path and build the maven project its working perfect .Thanks all

Sapna
  • 361
  • 2
  • 3
  • 17
1

I did the following change and it worked for me.Hope it helps someone.enter image description here

Kunal Khaire
  • 177
  • 1
  • 7
1

Add new JRE definition (select path JDK), worked for me.

http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-add_new_jre.htm

Lrodriguez84
  • 527
  • 4
  • 6
1

I was getting the same error when I created a new EC2 ubuntu 16.04 instance with Java already installed on it and while running mvn clean package, I encountered this issue and the below solution worked for me.

If you are working on an Ubuntu server, then you can try installing Java again and for that you can use this answer How to install the JDK on Ubuntu Linux

Ishan Ojha
  • 322
  • 3
  • 10
1

In Windows 7 - 64 bit, there is a permissions problem which prevents the installer from unpacking the file C:\Program Files\Java\jdk1.6.xx\lib\tools.jar into your local. This jar file is what maven-compiler-plugin version 3.x uses instead of the usual javac

Solution: Run, as an administrator, the Java JDK installer! And make sure the tools.jar is sitting in the C:\Program Files\Java\jdk1.6.xx\lib\

In case you are using m2e maven integration plugin, you want to see the file is visible to Eclipse via the following steps inside Eclipse:

Go to Window -> Preferences -> Java -> installed JREs Select the JDK you are using (C:\Program Files\Java\jdk1.6.xx) Press Edit to see the list of jars including tools.jar, OR you can add it as Add External JAR Then configure the maven run through these steps:

Run->Run configurations->Fill in Name, Base directory and Goals. Then in the same window move to the JRE tab and point to the JDK \jdk1.6.xx\

Parthiban
  • 381
  • 1
  • 7
  • 15
0

In addition to answer above, I could say that just try to run Maven from the terminal (outside of Eclipse). In this way, if it builds from outside but not in Eclipse, you can understand that the problem should be in Eclipse.

Ad Infinitum
  • 3,033
  • 19
  • 30
0

There are several answers regarding this question but all are related to right path configuration of JDK, but with JRE only we can solve this problem.

We just need to make use of deployment assembly to configure the path of packaged war file of the Java EE Project and then re-run the maven-install.

Steps to make use of deployment assembly:

  1. Right click on the Jave EE project --> click on Properties --> click on Deployment Assembly

  2. Click on Add button --> Click on Archives from the File System --> Click on next --> Click on Add --> Go to the .m2\respository directory and search for the war file generated --> Select war file --> Click on Open button --> Click on Apply --> OK

  3. Right click on the project --> Click on Maven Install under Run As

This will build your project successfully, without any compiler error.

Hope this solves the problem without JDK.

S Kumar
  • 533
  • 6
  • 15
0

Are you missing any maven build.

Apart from above JRE changes.I still faced similar issue.I was missing JUnit dependency after adding it is working fine.

Hope this will help.

0

I went to Preferences --> Java --> Installed JREs I did NOT see the JDK in here. I only saw the JRE here. So I added the JDK.

here we have to mandatory remove JRE instead of just unchecking.

Monika
  • 29
  • 4
0

right click on your project and run as maven install then again run your application. if this didnt work go to the folder of your project directly start command line and run 'mvn install'enter image description here