简体   繁体   English

Eclipse/Maven 错误:“此环境中未提供编译器”

[英]Eclipse/Maven error: "No compiler is provided in this environment"

I am a relative newcomer to the world of Java enterprise development.我是 Java 企业开发领域的新手。 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.我组织的 Java 大师无限期休假,我被分配了维护他开发的一些 Java 应用程序的任务。 He setup Eclipse [Kepler SR1] with Maven on my computer before he left, and it appeared to work ok.在他离开之前,他在我的电脑上用 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 [错误] 无法在项目 mrpapp 上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile): Compilation failure
[ERROR] No compiler is provided in this environment. [错误] 此环境中未提供编译器。 Perhaps you are running on a JRE rather than a JDK?也许您在 JRE 上运行而不是在 JDK 上运行?

but I definitely am running a JDK and not a JRE.但我肯定运行 JDK 而不是 JRE。 I double-checked my $JAVA_HOME ( C:\\Program Files (x86)\\Java\\jdk1.7.0_60 ) and it does have a javac.exe in its bin directory.我仔细检查了我的$JAVA_HOMEC:\\Program Files (x86)\\Java\\jdk1.7.0_60 ),它的bin目录有一个javac.exe

I am attaching a copy of my pom.xml file for your review.我附上我的pom.xml文件的副本供您查看。 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.我正在使用装有 Windows 7 64 位的笔记本电脑,如果您需要任何进一步的平台/环境信息,我也可以提供。

Any help will be greatly appreciated.任何帮助将不胜感激。

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 Edit button and put the path you configured your JAVA_HOME environment.并查看是否有指向您的JDK路径的条目,如果没有,请单击“编辑”按钮并将您配置的路径放在您的JAVA_HOME环境中。

Screen_shot Add 'tools.jar' to installed JRE. Screen_shot将“tools.jar”添加到已安装的 JRE。

  1. Eclipse -> window -> preference . Eclipse -> window -> preference
  2. Select installed JREs -> Edit选择installed JREs -> Edit
  3. Add External Jars添加外部罐子
  4. select tools.jar from java/JDKx.x/lib folder.java/JDKx.x/lib文件夹中选择tools.jar
  5. Click Finish单击完成

Go into Window > Preferences > Java > Installed JREs > and check your installed JREs.进入 Window > Preferences > Java > Installed JREs > 并检查您安装的 JREs。 You should have an entry with a JDK there.您应该在那里有一个带有 JDK 的条目。

https://cduu.wordpress.com/2013/03/08/maven-eclipse-compiler-error-no-compiler-is-provided-in-this-environment/ https://cduu.wordpress.com/2013/03/08/maven-eclipse-compiler-error-no-compiler-is-provided-in-this-environment/

I tried all the things;我尝试了所有的东西; the one that worked for me is:对我有用的是:

  1. Right click on Eclipse project and navigate to properties.右键单击 Eclipse 项目并导航到属性。
  2. Click on Java Build Path and go to the Libraries tab.单击 Java Build Path 并转到 Libraries 选项卡。
  3. Check which version of Java is added there;检查那里添加了哪个版本的 Java; is it JRE or JDK?是 JRE 还是 JDK?
  4. If you are using Maven project and want to build a solution.如果您正在使用 Maven 项目并希望构建解决方案。
  5. Select the JRE added their and click remove.选择添加了它们的 JRE,然后单击删除。
  6. Click Add external class folder and add the JDK install by selecting from the system.单击添加外部类文件夹并通过从系统中选择来添加 JDK 安装。
  7. Click Apply and OK.单击应用和确定。
  8. Restart Eclipse.重新启动 Eclipse。
  9. Build succeeded.构建成功。

Add this configurations in pom.xml在 pom.xml 中添加此配置

<project ...>
    ...
    <build>
        ...
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <fork>true</fork>
                    <executable>C:\Program Files\Java\jdk1.7.0_79\bin\javac</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>

I also faced similar error when I was working with Jdk1.8_92.我在使用 Jdk1.8_92 时也遇到过类似的错误。 For me, I found tools.jar was missing in my jdk folder.对我来说,我发现我的 jdk 文件夹中缺少 tools.jar。 Since I was running in console, I couldn't try the options of eclipse suggested by others..由于我是在控制台中运行,我无法尝试其他人建议的eclipse选项。

I installed jdk-8u92-windows-x64.我安装了 jdk-8u92-windows-x64。 After I tried all options, I observed that tools.jar was missing in jdk1.8.0_92/lib folder.在我尝试了所有选项后,我发现 jdk1.8.0_92/lib 文件夹中缺少 tools.jar。 I copied tools.jar from my older version of java.我从旧版本的 java 中复制了 tools.jar。 Then It was able to compile.然后它就可以编译了。

This worked for me.这对我有用。 1. Click on Window-> Preferences -> Installed JRE. 1.点击窗口->首选项->安装的JRE。 2. Check if you reference is for JDK as shown in the image below. 2. 检查您的参考是否适用于 JDK,如下图所示。 在此处输入图片说明

If not, Click on Add-> Standard VM -> Give the JDK path by selecting the directory and click on finish as shown in the image如果没有,单击添加-> 标准 VM -> 通过选择目录提供 JDK 路径,然后单击完成,如图所示在此处输入图片说明

  1. Last step, click on Installed JREs -> Execution Environments -> select your JDE as shown in the image below最后一步,点击 Installed JREs -> Execution Environments -> 选择你的 JDE,如下图所示在此处输入图片说明

  2. Maven -> Clean Maven -> 清洁

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>

if someone is running Eclipse in Ubuntu and have this problem I have found the answer by following these steps:如果有人在 Ubuntu 中运行 Eclipse 并遇到此问题,我可以按照以下步骤找到答案:

  1. Eclipse->window->preference. Eclipse->窗口->首选项。
  2. Select installed JREs->Add选择已安装的 JREs->Add
  3. Select standardVM.选择标准虚拟机。
  4. JRE home: press [Directory..] button. JRE 主页:按 [目录..] 按钮。
  5. 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.选择你的 java(我的问题是我的 eclipse 用 java8 运行,我的 VM 用 java7),在我的例子中 java8 安装在 usr/local/jvm/java-8-oracle 中。
  6. Press finish.按完成。
  7. Then press installed JRES arrow so you can see the other options.然后按已安装的 JRES 箭头,以便您可以看到其他选项。
  8. Go to Execution Environment.转到执行环境。
  9. 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).在左侧和右侧选择 JavaSE-1.6(兼容的 JRE),您必须选择刚刚安装的 Java(在我的例子中是 java-8-oracle)。 you have to do this steps with JavaSE1.8.您必须使用 JavaSE1.8 执行此步骤。
  10. Click OK and restart Eclipse.单击确定并重新启动 Eclipse。

I was getting the same error when trying to execute a maven build within Eclipse in a newly installed Eclipse Neon (for JEE devs) installation, on Windows 10 with JDK 8 and JRE 8 installed.在安装了 JDK 8 和 JRE 8 的 Windows 10 上,尝试在新安装的 Eclipse Neon(适用于 JEE 开发人员)安装中在 Eclipse 中执行 maven 构建时遇到相同的错误。

I had tried specifying tools.jar as an external lib, as well as setting the jdk as the -vm in eclipse.我曾尝试将 tools.jar 指定为外部库,并将 jdk 设置为 eclipse 中的 -vm。 Neither of these things worked.这些事情都没有奏效。

Selecting the JDK as the default execution env as mentioned above did the trick..如上所述,选择 JDK 作为默认执行环境就可以了。

  1. Eclipse->window->preference->java->Installed JREs->Execution Environments. Eclipse->window->preference->java->Installed JREs->Execution Environments。
  2. Select JavaSE-1.8选择 JavaSE-1.8
  3. Check JDK1.8 in "Compatible JREs".在“Compatible JREs”中检查JDK1.8。

The text above the compatible JREs listbox in step 3 says "a default JRE can be specified by checking it"步骤 3 中兼容 JRE 列表框上方的文本表示“可以通过检查指定默认 JRE”

Note: I also have the maven compiler plugin explicitly listing 1.8 in the pom注意:我还有 maven 编译器插件在 pom 中明确列出 1.8

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

安装 JRE在我的情况下,我通过删除重复的名称解决了这个问题,我只保留了一个名称:jdk.1.8.0_101

Follow : Windows --> Preferences --> Java ---> Installed JREs按照: Windows -->首选项--> Java --->已安装的JRE

SampleImage示例图像

Click on " Search .."点击“搜索..”

Navigate to C drive ---> Program files导航到C盘--->程序文件

Sample Image 2示例图像 2

Eclipse will find all the jre's and jdk's --> select one of the jdk and select Apply Eclipse 会找到所有的 jre 和 jdk --> 选择jdk 之一并选择 Apply

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).在一些网站上搜索后,我编辑了运行配置并在 JRE 选项卡下,将运行时 JRE 选择为“工作区默认 JRE”,我已经将其配置为指向我的本地 Java JDK 安装(例如 C:\\Program Files (x86)) \\Java\\jdk1.8.0_51)。 This solved my issue.这解决了我的问题。 Maybe it helps someone out there.也许它可以帮助那里的人。

was getting the same problem, pointed java to bin folder in eclipse using: windows > preferences > java > installed JREs > remove any existing JRE and point it to your java bin folder (mainly under C:\\Program Files\\Java\\jdk1.8.x_xx).遇到了同样的问题,使用以下方法将 java 指向 eclipse 中的 bin 文件夹:windows > 首选项 > java > 已安装的 JRE > 删除任何现有的 JRE 并将其指向您的 java bin 文件夹(主要在 C:\\Program Files\\Java\\jdk1.8 下) .x_xx)。

then run maven install it should work.然后运行 ​​maven install 它应该可以工作。

To check what your Maven uses, open a command line and type:要检查您的 Maven 使用什么,请打开命令行并键入:

mvn –version

Verify that JAVA_HOME refers to a JDK home and not a JRE验证 JAVA_HOME 是否指的是 JDK home 而不是 JRE

On Windows:在 Windows 上:

Go to System properties -> Advanced system settings -> Advanced -> environment variable and on the System variables section select the JAVA_HOME variable and click on Edit Fill the form with the following Variable name: JAVA_HOME Variable value:转到系统属性 -> 高级系统设置 -> 高级 -> 环境变量并在系统变量部分选择 JAVA_HOME 变量并单击编辑 使用以下变量名称填写表单:JAVA_HOME 变量值:

On Unix:在 Unix 上:

export JAVA_HOME=<ABSOLUTE_PATH_TO_JDK>

see this link看到 这个链接

When I was runing mvn compile , I was getting below error in console:当我运行mvn compile ,我在控制台中遇到以下错误:

[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1087 source files to C:\Code\DevVNextComplete\Development_vNext\Source\JARS\target\classes
[INFO] -------------------------------------------------------------
[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

[Resolution] [解决]

I had added, the JAVA_HOME variable in my environment variables and then it worked.我在我的环境变量中添加了 JAVA_HOME 变量,然后它起作用了。

在此处输入图片说明

  1. 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从系统中卸载旧的 Java(JDK/JRE)(保留一个(最新的)java 版本),如果环境变量 PATH/CLASSPATH 中有任何旧的 java jre/jdk 条目,也删除
  2. Eclipse->Window->Preferences->Installed JREs->Add/Edit JDK from the latest installation Eclipse->Window->Preferences->Installed JREs->Add/Edit JDK from the latest installation
  3. Eclipse->Window->Preferences->Installed JREs->Execution Environment->Select the desired java version on left and click the check box on right Eclipse->Window->Preferences->Installed JREs->Execution Environment->左侧选择想要的java版本,点击右侧的复选框
  4. If you are using maven include the following tag in pom.xml (update versions as needed) inside plugins tag.如果您使用 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>
  5. Right click on eclipse project Maven - > Update Project右键单击 Eclipse 项目 Maven -> 更新项目

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 .对我来说(在 Windows 10 上),当我运行mvn install时,我在 Windows 命令提示符下收到错误“此环境中没有提供编译器”。 The fix was changing the JAVA_HOME environment variable to point to my jdk (C:\\Program Files\\Java\\jdk1.8.0_101);修复是将JAVA_HOME环境变量更改为指向我的 jdk (C:\\Program Files\\Java\\jdk1.8.0_101); previously it had pointed to the jre.以前它指向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 发行版中编辑了eclipse.ini并将-vm的行更改为C:\\Program Files\\Java\\jdk1.8.0_101\\bin

check java version in pom.xml and jre version in Eclipse->Window->Preferences->Installed JREs.检查 pom.xml 中的 java 版本和 Eclipse->Window->Preferences->Installed JREs 中的 jre 版本。 In my case pom.xml has different version(it had 1.8 while eclipse using 1.7).在我的例子中,pom.xml 有不同的版本(它有 1.8,而 eclipse 使用 1.7)。 Fixing the version in pom.xml to 1.7 worked.将 pom.xml 中的版本修复为 1.7 有效。

if you are working outside of eclipse in the command window如果您在命令窗口中的 eclipse 之外工作
make sure you have the right JAVA_HOME and that that directory contains the compiler by entering the following command in the command window:通过在命令窗口中输入以下命令,确保您拥有正确的 JAVA_HOME 并且该目录包含编译器:

dir %JAVA_HOME%\bin\javac.*

1.Go to Windows-->Preferences-->Java-->Installed JREs-->Execution Environments 1.进入Windows-->Preferences-->Java-->Installed JREs-->Execution Environments

2.select the java version you are using currently in the "Execution Environments" box. 2.在“执行环境”框中选择您当前使用的java版本。 So that in the "Compatible JREs" box, you are able to see as " jre1.8.0_102[perfect match] "(if your java version is 1.8).因此,在“Compatible JREs”框中,您可以看到“ jre1.8.0_102[perfect match] ”(如果您的Java 版本是1.8)。 Then try to build using maven.然后尝试使用 maven 构建。

Maven requires JDK to compile. Maven 需要 JDK 才能编译。 In Eclipse you need to CHANGE/ REPLACE your JRE to the JDK path that your JAVA_HOME points to.在 Eclipse 中,您需要将 JRE 更改/替换为 JAVA_HOME 指向的 JDK 路径。 Navigate to Window > Preferences > Java > Installed JREs.导航到“窗口”>“首选项”>“Java”>“已安装的 JRE”。

Make sure that the maven-compiler-plugin in you pom.xml has the source and target of the java version in your JAVA_HOME确保你的 pom.xml 中的 maven-compiler-plugin 在你的 JAVA_HOME 中有 java 版本的源和目标

http://learn-automation.com/maven-no-compiler-is-provided-in-this-environment-selenium/ http://learn-automation.com/maven-no-compiler-is-provided-in-this-environment-selenium/

Make sure you have %JAVA_HOME% set by typing echo %JAVA_HOME% in Command Prompt.请确保您有%JAVA_HOME%通过键入SET echo %JAVA_HOME%在命令提示符。 If you don't have that set, then you need to go add your Java path to Window's Environmental Variables.如果您没有该设置,那么您需要将您的 Java 路径添加到 Window 的环境变量中。

我通过在我的环境变量中提供 JAVA_HOME 并重新启动 intellij 解决了这个问题

you can follow any of one from given below.您可以按照下面给出的任何一个进行操作。

  1. Project--properties--java build path--jre system library--edit--add library path as JDK项目--属性--java构建路径--jre系统库--编辑--添加库路径为JDK
  2. Window preference--java--installed JRE--JRE system library--add library and provide path to JDK folder窗口首选项--java--安装的JRE--JRE系统库--添加库并提供JDK文件夹的路径
  3. You will have to instruct eclipse to use JDK as build/compile source in some ways if it's configured to point to jre instead For default compiler如果它被配置为指向 jre,你将不得不以某种方式指示 eclipse 使用 JDK 作为构建/编译源 对于默认编译器

If none of the above helped still You are facing the same issue means you may have misconfigurations in your Custom Run/Debug Configurations.如果以上方法仍然没有帮助您面临同样的问题意味着您的自定义运行/调试配置中可能存在错误配置。

In My case I am using a Custom maven run configuration.就我而言,我使用的是自定义 Maven 运行配置。 There the JRE is pointed earlier.前面提到了 JRE。 Once I changed it to JRK it worked as expected.一旦我将其更改为 JRK,它就会按预期工作。
在此处输入图片说明

I had a problem with Eclipse Neon where the workspace default did not actually change even though I added the correct location under Preferences->Java->Installed JREs.我在使用 Eclipse Neon 时遇到了一个问题,即使我在 Preferences->Java->Installed JREs 下添加了正确的位置,工作区默认值实际上并没有改变。 This was in a new workspace I created to work on a code branch;这是在我创建的一个新工作区中,用于处理代码分支; it was originally set to the JRE location rather than the JDK.它最初设置为 JRE 位置而不是 JDK。 Yet even after changing the preferences, I could build with the command line, yet building in Eclipse produced the no compiler error.然而,即使在更改首选项之后,我也可以使用命令行进行构建,但在 Eclipse 中构建会产生无编译器错误。 Please see请参阅

Maven Package Compilation Error Maven 包编译错误

for my answer on which Eclipse configuration file(s) had to be manually edited to make Eclipse recognize the correct workspace default.对于我必须手动编辑哪些 Eclipse 配置文件才能使 Eclipse 识别正确的工作区默认值的答案。 I still have no idea why the preferences setting did not carry through to the new workspace's configuration.我仍然不知道为什么首选项设置没有贯彻到新工作区的配置中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM