可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
i created a webapp project using maven in eclipse. when i run the command mvn package in command prompt it showing folowing 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: 4.310s [INFO] Finished at: Tue Mar 05 14:32:23 IST 2013 [INFO] Final Memory: 16M/218M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project Compilation fa ilure [ERROR] ***No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?*** [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
i tried to change jdk and jre. but not working. still it shows same error
回答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, OW 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\
回答2:
Go to your 'Runtime Configuration' and configure your JRE to an JDK.

Or as @PawanKumarBaranwal suggested, set your default JDK. But care if you have more than one JRE configured.

回答3:
What worked for me (32-Bit Windows 7) was to add the following to your path environment variable:
%JAVA_HOME%\lib;
回答4:
Try this. Go to Window --> Preferences --> Java --> Installed JREs.
Double click the JRE, which is inside installed JREs.
Give the JDK path (for example, C:\Program Files\Java\jdk1.7.0_80\
) in JRE Home, and give JRE name as JDK. Click on Finish and then OK.
For me it worked.
回答5:
In my case, the error "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK" was due to the JRE being installed in a different location than its default under the JDK.
Running under 64-bit linux, I have Oracle's 64-bit JDK SE 1.6.0_45 installed at /opt/java
. The 32 and 64 bit JRE's were installed at /opt/java/jre32
and /opt/java/jre64
, with a jre symlink: (ie. ln -s jre64 jre
), sojre ->
./jre64(meaning
/opt/jdk/jrewas a symlink referencing
/opt/jdk/jre64).
Once I renamed jre64 to jre (ie. rm jre ; mv jre64 jre ; ln -s jre jre64
), this problem went away; and I was able to build using maven (inside of netbeans).
Maven appears to be looking at the JRE path, saying "jre64 isn't the correct name for a default JRE-inside-of-JDK install, so assume a JDK doesn't exist at ../"), which would prevent it from resolving the location of the JDK lib directory containing tools.jar, etc.
Haven't tested it, but the same thing might happen under Windows if the JRE isn't in the default location (or perhaps isn't in the %JAVA_HOME%\jre
directory). If both the JDK and the JRE are installed, Oracle's installer wants to install the JRE at %JAVA_HOME%\jre6
, not %JAVA_HOME%\jr
e. That may be because the \jre
directory is needed for the JDK uninstall process; if the JRE has been installed on top of the JDK's JRE in the \jre
directory, instead of at \jre
6, uninstalling the JDK after the uninstalling the JRE will fail unless the \jre directory is copied, JRE is uninstalled, and the \jre
copy is restored to \jre
.
回答6:
Go to preferences>installed JRE>
then click add
select C:\program files\java\
press enter
it will search for other jre's than jdk and then choose what is not selected
回答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 1) Workspace Default JRE is set from 'Window' menu on the top -> Preferences -> Java -> Installed JREs -Here you can add your jdk 2) Execution Environment jdk can be set in pom.xml
maven-compiler-plugin3.1trueC:\Program Files\Java\jdk1.7.0_45\bin\javac.exe
3) Alternate JRE can be used to select a jdk from your directory
回答8:
Go to windows -> Preferences -> Java -> Installed JREs
may be jre is already added 
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 this

select JDK -> Apply -> Ok
And You are done.
回答9:
to set path in below manner
keep jdk's path at first place in path variable, so that other java path will be ignored. compilation error will be resolved.
回答10:
I'm using maven plugin for Eclipse (V3.3) and was struggling with this error for a while. I finally found the solution which is linked to stale java sources: it has nothing to do with JRE or JDK (I use JRE 1.7).
I found on other forums that it is a known problem in maven-compiler-plugin (same result for V3.3 and 3.5.1).
So, I just recompiled manually the stale source(s) and ran again the goal, this time without any problem.
To figure out stale sources, run the goal with option -X (debug) and look for entries beginning with
[DEBUG] Stale source detected:
indicating a java class file (to be recompiled manually...).
Hope this can be useful as the message given by maven compiler made me search in a wrong direction (play with JRE, JDK, JAVA-HOME, etc).