eclipse Java 编译器级别与已安装 Java 项目方面的版本不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7715260/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:35:17  来源:igfitidea点击:

Java compiler level does not match the version of the installed Java project facet

eclipsemavenm2eclipse

提问by user974802

I have created a New Dynamic Project under Eclipse Helios Version, where my JRE Version is set to 1.6. I have added Maven capabilities to the Web Application by clicking on ConfigureConvert to Maven Project.

我在 Eclipse Helios 版本下创建了一个新的动态项目,其中我的 JRE 版本设置为 1.6。我通过单击ConfigureConvert to Maven Project向 Web 应用程序添加了 Maven 功能。

After adding this, a build error appeared in the Eclipse Problems view:

添加后,Eclipse Problems 视图中出现构建错误:

Java compiler level does not match the version of the installed Java project facet.
Unknown Faceted Project Problem (Java Version Mismatch)

Please tell me how to resolve this error (I want to have my JRE version as 1.6 only).

请告诉我如何解决此错误(我希望我的 JRE 版本仅为 1.6)。

采纳答案by Vineet Reynolds

Assuming that you are using the m2e plugin in Eclipse, you'll need to specify the sourceand targetversions as 1.6 for maven-compiler-plugin. m2e uses these values to determine the project's Java compiler level. A snippet of the POM is shown below:

假设您在 Eclipse 中使用 m2e 插件,您需要将sourcetarget版本指定为 1.6 for maven-compiler-plugin. m2e 使用这些值来确定项目的 Java 编译器级别。POM 的一个片段如下所示:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
    </plugin>
  </plugins>
</build>

Alternatively, you can specify the maven.compiler.sourceand maven.compiler.targetproperties with values of 1.6, that happen to be the equivalent:

或者,您可以指定值为 1.6的maven.compiler.sourcemaven.compiler.target属性,这恰好是等效的:

<properties>
    <maven.compiler.target>1.6</maven.compiler.target>
    <maven.compiler.source>1.6</maven.compiler.source>
</properties>

回答by TK Gospodinov

If your project is not a Maven project, right-click on your project and choose Properties to open the Project Properties dialog.

如果您的项目不是 Maven 项目,请右键单击您的项目并选择“属性”以打开“项目属性”对话框。

There is a Project Facets item on the left, select it, look for the Java facet on the list, choose which version you want to use for the project and apply.

左侧有一个 Project Facets 项,选择它,在列表中查找 Java facet,选择要用于项目的版本并应用。

Project Factes - Java version

项目事实 - Java 版本

回答by Nestor Urquiza

TK Gospodinov answer is correct even for maven projects. Beware: I do use Maven. The pom was correct and still got this issue. I went to "Project Facets" and actually removed the Java selection which was pointing to 1.6 but my project is using 1.7. On the right in the "Runtimes" tab I had to check the jdk1.7 option. Nothing appeared on the left even after I hit "Apply". The issue went away though which is why I still think this answer is important of the specific "Project Facets" related issue. After you hit OK if you come back to "Project Facets" you will notice Java shows up as version 1.7 so you can now select it to make sure the project is "marked" as a Java project. I also needed to right click on the project and select Maven|Update Project.

即使对于 Maven 项目,TK Gospodinov 的答案也是正确的。当心:我确实使用 Maven。pom 是正确的,但仍然有这个问题。我去了“Project Facets”,实际上删除了指向 1.6 的 Java 选择,但我的项目使用的是 1.7。在“运行时”选项卡的右侧,我必须检查 jdk1.7 选项。即使在我点击“应用”之后,左侧也没有出现任何内容。问题消失了,这就是为什么我仍然认为这个答案对于特定的“Project Facets”相关问题很重要。如果您返回到“Project Facets”,点击 OK 后,您会注意到 Java 显示为 1.7 版,因此您现在可以选择它以确保该项目被“标记”为 Java 项目。我还需要右键单击该项目并选择 Maven|Update Project。

回答by Freelancer

I resolved this problem by setting the java version in Project Facet property of the project properties, Right click the project root folder -> Properties, search for Project Facets, and select compatible java version.

我通过在项目属性的Project Facet属性中设置java版本解决了这个问题,右键单击项目根文件夹->属性,搜索Project Facets,然后选择兼容的java版本。

For reference -

以供参考 -

enter image description here

在此处输入图片说明

回答by thedheeraz

I changed the configuration inside workspace/project/.setting/org.eclipse.wst.common.project.facet.coreto :

我将里面的配置workspace/project/.setting/org.eclipse.wst.common.project.facet.core改为:

installed facet="jst.web" version="2.5"
installed facet="jst.java" version="1.7"

Before changing config, remove project from IDE. This worked for me.

在更改配置之前,从 IDE 中删除项目。这对我有用。

回答by RishiKesh Pathak

I resolved it by Myproject--->java Resource---->libraries-->JRE System Libraries[java-1.6]click on this go to its "property" select "Classpath Container"change the Execution Environmentto java-1.8(jdk1.8.0-35) (that is latest)

我通过Myproject---> java Resource----> libraries--> J RE System Libraries[java-1.6]解决了这个问题,点击它的“属性”选择“Classpath Container”执行环境更改为 java- 1.8(jdk1.8.0-35)(即最新

Change the jdk to latest

将 jdk 更改为最新

回答by Anant Laxmikant Bobde

You can change project facet from Project --> Properties --> Project Facet --> Java --> {required JDK version}

您可以从 Project --> Properties --> Project Facet --> Java --> {required JDK version} 更改项目方面

回答by user3925215

The Project Facet->Java should match whatever you have in the pom.xml for the maven-compiler-plugin artifact source and target.This is perfect.But if you donot have it here then you can also fix it by matching Java compiler version in Porject-Facets from the setting: Eclispe->Preferences->Java->Compiler

Project Facet->Java 应该匹配您在 pom.xml 中为 maven-compiler-plugin 工件源和目标所拥有的任何内容。这是完美的。但是如果您在这里没有它,那么您也可以通过匹配 Java 编译器版本来修复它在 Porject-Facets 中的设置:Eclispe->Preferences->Java->Compiler

回答by Raphael

Right click the project and select properties Click the java compiler from the left and change to your required version Hope this helps

右键单击项目并选择属性单击左侧的java编译器并更改为您需要的版本希望这有帮助

回答by Danilo Lira

In Eclipse, right click on your project, go to Maven> Update projetc. Wait and the error will disappear. This is already configured correctly the version of Java for this project.

在 Eclipse 中,右键单击您的项目,转到 Maven> Update projetc。等待,错误将消失。这已经为该项目正确配置了 Java 版本。

enter image description here

在此处输入图片说明