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

来源:互联网 发布:sql create table 编辑:程序博客网 时间:2024/05/10 13:23

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

up vote137down votefavorite
33

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 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?
shareimprove this question
 
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 – mlt Aug 17 '15 at 18:56

10 Answers

activeoldestvotes
up vote225down voteaccepted

Go into Window > Preferences > Java > Installed JREs > and check your installed JREs. You should have an entry with a JDK there. Select the Execution Env as show below. Click OK 
Then RightClick Project -> Maven -> Update Project

enter image description here

shareimprove this answer
 
 
Perfect Solution. Thanks! – Robin Feb 5 '14 at 13:28
2 
@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 3:50
1 
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 4:28
9 
@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
2 
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 1 '15 at 11:19
up vote24down vote

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

shareimprove this answer
 
1 
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 1 '15 at 11:18
 
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 at 2:40
up vote23down vote

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:

-vmC:\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.

shareimprove this answer
 
1 
Woo.. This is the answer that worked for me, thanks a ton (Y) – Saumil Soni Nov 24 '14 at 12:27
up vote17down vote
  1. Set JAVA_HOME to JDK root - required if you run command line or maven(google for this variable)
  2. In project properties in section Java Compiller select required JDK - if you run directly from eclipse
shareimprove this answer
 
 
Why is step 1 required? – Duncan Oct 29 '13 at 10:33
 
@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. – DuncanOct 29 '13 at 15:21
1 
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
up vote13down vote

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

shareimprove this answer
 
2 
Thx This made it for me! – Igor Zelaya Aug 18 '15 at 2:57
 
This appears to be necessary to check in addition to the selected answer above. – nsandersen Sep 24 '15 at 13:55
 
This solution is not working in my case. – Athlan Oct 3 '15 at 13:47
up vote1down vote

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.

shareimprove this answer
 
1 
At least you're being honest. ;) – Cyntech Feb 10 at 3:29
up vote0down vote

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.

shareimprove this answer
 
up vote0down vote

Try this.

... ... maven-compiler-plugin 3.1 true path to jdk \bin\javac.exe

shareimprove this answer

转自:http://stackoverflow.com/questions/19655184/no-compiler-is-provided-in-this-environment-perhaps-you-are-running-on-a-jre-ra
0 0