Java Eclipse/Maven 错误:“此环境中未提供编译器”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21099072/
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
Eclipse/Maven error: "No compiler is provided in this environment"
提问by Ken L
I am a relative newcomer to the world of Java enterprise development. My organization's Java guru is out on indefinite family leave, and I have been assigned the task of maintaining some of the Java applications he developed. He setup Eclipse [Kepler SR1] with Maven on my computer before he left, and it appeared to work ok.
我是 Java 企业开发领域的新手。我组织的 Java 大师无限期休假,我被分配了维护他开发的一些 Java 应用程序的任务。在他离开之前,他在我的电脑上用 Maven 设置了 Eclipse [Kepler SR1],它似乎工作正常。
Now I'm ready to deploy my first modification and need to run a Maven install
, but I am having trouble getting it to work - I get the following output on my console:
现在我准备部署我的第一个修改并需要运行 Maven install
,但我无法让它工作 - 我在我的控制台上得到以下输出:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project mrpapp: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[错误] 无法在项目 mrpapp 上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile): Compilation failure
[ERROR] 此环境中未提供编译器。也许您在 JRE 而不是 JDK 上运行?
but I definitely amrunning a JDK and not a JRE. I double-checked my $JAVA_HOME
(C:\Program Files (x86)\Java\jdk1.7.0_60
) and it doeshave a javac.exe
in its bin
directory.
但我肯定在运行 JDK 而不是 JRE。我仔细检查了我的$JAVA_HOME
( C:\Program Files (x86)\Java\jdk1.7.0_60
),它的目录中确实有一个。javac.exe
bin
I am attaching a copy of my pom.xml
file for your review. I'm sure there is something in there that is causing the problem, but I am not sure what it might be. I am using a laptop with Windows 7 64bit, if you need any further platform/environment info I can supply that as well.
我附上我的pom.xml
文件副本供您查看。我确定那里有什么东西导致了这个问题,但我不确定它可能是什么。我正在使用装有 Windows 7 64 位的笔记本电脑,如果您需要任何其他平台/环境信息,我也可以提供。
Any help will be greatly appreciated.
任何帮助将不胜感激。
采纳答案by Jorge Campos
Go to Window → Preferences → Java → Installed JREs.
转到窗口 → 首选项 → Java → 已安装的 JRE。
And see if there is an entry pointing to your JDK path, and if not, click on Editbutton and put the path you configured your JAVA_HOME
environment.
并查看是否有指向您的JDK路径的条目,如果没有,请单击“编辑”按钮并将您配置的路径放在您的JAVA_HOME
环境中。
回答by Gubatron
Go into Window > Preferences > Java > Installed JREs > and check your installed JREs. You should have an entry with a JDK there.
进入 Window > Preferences > Java > Installed JREs > 并检查您安装的 JREs。您应该在那里有一个带有 JDK 的条目。
回答by Balaji
Please check if you have the following entries in the element of your pom.xml especially the jdk.version because switching to an installed jre did not fix me the similar error.
请检查您的 pom.xml 元素中是否有以下条目,尤其是 jdk.version,因为切换到已安装的 jre 并没有修复类似的错误。
<properties>
<jdk.version>1.7</jdk.version>
<spring.version>4.1.1.RELEASE</spring.version>
<jstl.version>1.2</jstl.version>
<junit.version>4.11</junit.version>
</properties>
回答by Archana Prasad
I tried all the things; the one that worked for me is:
我尝试了所有的东西;对我有用的是:
- Right click on Eclipse project and navigate to properties.
- Click on Java Build Path and go to the Libraries tab.
- Check which version of Java is added there; is it JRE or JDK?
- If you are using Maven project and want to build a solution.
- Select the JRE added their and click remove.
- Click Add external class folder and add the JDK install by selecting from the system.
- Click Apply and OK.
- Restart Eclipse.
- Build succeeded.
- 右键单击 Eclipse 项目并导航到属性。
- 单击 Java Build Path 并转到 Libraries 选项卡。
- 检查那里添加了哪个版本的 Java;是 JRE 还是 JDK?
- 如果您正在使用 Maven 项目并希望构建解决方案。
- 选择添加了它们的 JRE,然后单击删除。
- 单击添加外部类文件夹并通过从系统中选择来添加 JDK 安装。
- 单击应用和确定。
- 重新启动 Eclipse。
- 构建成功。
回答by Marcelo Gomez
if someone is running Eclipse in Ubuntu and have this problem I have found the answer by following these steps:
如果有人在 Ubuntu 中运行 Eclipse 并遇到此问题,我可以按照以下步骤找到答案:
- Eclipse->window->preference.
- Select installed JREs->Add
- Select standardVM.
- JRE home: press [Directory..] button.
- Choose your java (my problem was my eclipse was running with java8 and my VM were with java7), in my case java8 was installed in usr/local/jvm/java-8-oracle.
- Press finish.
- Then press installed JRES arrow so you can see the other options.
- Go to Execution Environment.
- Select JavaSE-1.6 on left and in the right (the compatible JRE) you have to choose the Java you have just installed( in my case java-8-oracle). you have to do this steps with JavaSE1.8.
- Click OK and restart Eclipse.
- Eclipse->窗口->首选项。
- 选择已安装的 JREs->Add
- 选择标准虚拟机。
- JRE 主页:按 [目录..] 按钮。
- 选择你的 java(我的问题是我的 eclipse 用 java8 运行,我的 VM 用 java7),在我的例子中 java8 安装在 usr/local/jvm/java-8-oracle 中。
- 按完成。
- 然后按已安装的 JRES 箭头,以便您可以看到其他选项。
- 转到执行环境。
- 在左侧和右侧选择 JavaSE-1.6(兼容的 JRE),您必须选择刚刚安装的 Java(在我的例子中是 java-8-oracle)。您必须使用 JavaSE1.8 执行此步骤。
- 单击确定并重新启动 Eclipse。
回答by Manish
I also faced similar error when I was working with Jdk1.8_92. For me, I found tools.jar was missing in my jdk folder. Since I was running in console, I couldn't try the options of eclipse suggested by others..
我在使用 Jdk1.8_92 时也遇到过类似的错误。对我来说,我发现我的 jdk 文件夹中缺少 tools.jar。由于我是在控制台中运行,我无法尝试其他人建议的eclipse选项。
I installed jdk-8u92-windows-x64. After I tried all options, I observed that tools.jar was missing in jdk1.8.0_92/lib folder. I copied tools.jar from my older version of java. Then It was able to compile.
我安装了 jdk-8u92-windows-x64。在我尝试了所有选项后,我发现 jdk1.8.0_92/lib 文件夹中缺少 tools.jar。我从旧版本的 java 中复制了 tools.jar。然后它就可以编译了。
回答by Jatin Shashoo
In my case, I had created a run configuration and whenever I tried to run it, the error would be displayed. After searching on some websites, I edited the run configuration and under JRE tab, selected the runtime JRE as 'workspace default JRE' which I had already configured to point to my local Java JDK installation (ex. C:\Program Files (x86)\Java\jdk1.8.0_51). This solved my issue. Maybe it helps someone out there.
就我而言,我创建了一个运行配置,每当我尝试运行它时,都会显示错误。在一些网站上搜索后,我编辑了运行配置并在 JRE 选项卡下,将运行时 JRE 选择为“工作区默认 JRE”,我已经将其配置为指向我的本地 Java JDK 安装(例如 C:\Program Files (x86)) \Java\jdk1.8.0_51)。这解决了我的问题。也许它可以帮助那里的人。
回答by sibabrata
Screen_shotAdd 'tools.jar' to installed JRE.
Screen_shot将“tools.jar”添加到已安装的 JRE。
Eclipse
->window
->preference
.- Select
installed JREs
->Edit
- Add External Jars
- select
tools.jar
fromjava/JDKx.x/lib
folder. - Click Finish
Eclipse
->window
->preference
。- 选择
installed JREs
->Edit
- 添加外部罐子
tools.jar
从java/JDKx.x/lib
文件夹中选择。- 单击完成
回答by Bruce
- Uninstall older Java(JDK/JRE) from the system( Keep one (latest) java version), Also remove if any old java jre/jdk entries in environment variables PATH/CLASSPATH
- Eclipse->Window->Preferences->Installed JREs->Add/Edit JDK from the latest installation
- Eclipse->Window->Preferences->Installed JREs->Execution Environment->Select the desired java version on left and click the check box on right
If you are using maven include the following tag in pom.xml (update versions as needed) inside plugins tag.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin>
- Right click on eclipse project Maven - > Update Project
- 从系统中卸载旧的 Java(JDK/JRE)(保留一个(最新的)java 版本),如果环境变量 PATH/CLASSPATH 中有任何旧的 java jre/jdk 条目,也删除
- Eclipse->Window->Preferences->Installed JREs->Add/Edit JDK from the latest installation
- Eclipse->Window->Preferences->Installed JREs->Execution Environment->左侧选择想要的java版本,点击右侧的复选框
如果您使用 maven,请在 pom.xml 中的插件标签内(根据需要更新版本)包含以下标签。
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin>
- 右键单击 Eclipse 项目 Maven -> 更新项目
回答by Don Smith
For me (on windows 10), I was getting the error "No compiler is provided in this environment" at the Windows command prompt when I ran mvn install
. The fix was changing the JAVA_HOMEenvironment variable to point to my jdk (C:\Program Files\Java\jdk1.8.0_101); previously it had pointed to the jre.
对我来说(在 Windows 10 上),当我运行mvn install
. 修复是将JAVA_HOME环境变量更改为指向我的 jdk (C:\Program Files\Java\jdk1.8.0_101);以前它指向jre。
And to get Eclipse to use the new jdk, I edited eclipse.ini
in my eclipse distribution and changed the line for -vm
to C:\Program Files\Java\jdk1.8.0_101\bin
.
而让Eclipse中使用新的JDK,我编辑eclipse.ini
我的Eclipse发行,改变了线-vm
对C:\Program Files\Java\jdk1.8.0_101\bin
。