Java 此环境中不提供编译器。也许您在 JRE 而不是 JDK 上运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19655184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
提问by Sai prateek
I'm compiling a project in Eclipse using m2eclipse. I set the JDK path in Eclipse like this:
我正在使用 m2eclipse 在 Eclipse 中编译一个项目。我在 Eclipse 中设置 JDK 路径是这样的:
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?
采纳答案by jaipster
- 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.
- Select the Execution Env as show below. Click OK
- Then Right-Clickon your Project -> Maven-> Update Project
- 在您的 Eclipse IDE 上,进入Window> Preferences> Java> Installed JREs> 并检查您安装的 JREs。您应该在那里有一个带有 JDK 的条目。
- 选择执行环境,如下所示。单击确定
- 然后右键单击您的项目 -> Maven->更新项目
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
此外,您可能需要更改 Maven JRE(请参阅 @jlars62 答案),如下所示。转到 Run -> Run Configurations,选择我正在运行的 Maven Build(从左侧面板)。然后,我单击 JRE 选项卡并选择了选项 Workspace default JRE
回答by msangel
- 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)
- (Search google for
- In project properties in section Java Compiler select required JDK - if you run directly from eclipse
- 将
JAVA_HOME
环境变量设置为 JDK 根文件夹 - 如果您运行命令行或 maven (mvn
),则需要。- (搜索谷歌
JAVA_HOME
了解更多信息)
- (搜索谷歌
- 在 Java Compiler 部分的项目属性中选择所需的 JDK - 如果您直接从 eclipse 运行
回答by ksnortum
For me, nothing worked until I made this change to my pom.xml:
对我来说,在我对 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:
我可以看到 m2e 在 JRE 中执行,而不是在 JDK 中执行。我没有做任何改变,包括将它添加到 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.
最后,我从来没有让 m2e 在 JDK 中执行,但是显式设置 Java 编译器(如上所述)可以解决问题。
回答by brunoais
An alternative if jaipster's answer does not work is to go to:
Window > Preferences > Java > Installed JREs
如果 jaipster 的答案不起作用,另一种方法是转到:
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)
然后编辑 jre,使其指向 jdk 而不是 jre(在 jre 包编辑器中归档的 jre home)
That worked for me.
那对我有用。
回答by Thai Tran
For me, it is exactly what the maven of eclipse complains
对我来说,这正是 eclipse 的专家抱怨的
So, I press Edit
button and change path to the JDK Folder, then clean project and everything starts to work
所以,我按下Edit
按钮并更改 JDK 文件夹的路径,然后清理项目,一切都开始工作
回答by jlars62
I was getting this error when trying to do a maven build from within eclipse.
尝试从 Eclipse 中进行 Maven 构建时出现此错误。
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
对我来说,答案是Run
-> Run Configurations
,选择Maven Build
I was running (从左侧面板)。然后,我单击JRE
选项卡并选择了选项Workspace default JRE
回答by Wagh
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>
回答by Sapna
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
我遇到了同样的问题,我犯的错误是我只在路径 var 中添加了 jre 路径,而不是 jdk 路径。当 jdk 路径添加到路径并构建 Maven 项目时,它的工作完美。谢谢
回答by Kunal Khaire
回答by Sam
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).
安装 JDK 时,安装程序会询问您要将文件安装到何处。默认情况下,在 Windows 上,这类似于 C:\Program Files\Java\jdk1.8.0_74(或您正在安装的任何版本)。
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.
然后它会要求您提供一个用于安装 JRE 的目录,默认情况下该目录类似于 C:\Program Files\Java\jre1.8.0_74。
Note that one is jdk1.8.0_74 and the other is jre1.8.0_74
注意一个是jdk1.8.0_74,另一个是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.
我很着急,认为安装程序两次问我同样的问题,将我的 JDK 和 JRE 安装位置都设置为 D:\devtools\jdk\jdk1.8.0_74,导致安装程序用 JRE 覆盖了 JDK。这导致(除其他外)我的 JDK bin 中缺少 javac.exe,并且 OP 在我的所有 maven 构建中报告了相同的错误。