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

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

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

请告诉我如何解决这个错误(我想有我的JRE版本为1.6)。


当前回答

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

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

或者,你可以指定maven.compiler.source和maven.compiler.target属性的值为1.6,这恰好是等价的:

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

其他回答

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.

我通过Myproject- >java Resource---->libraries- >JRE System libraries [java-1.6]单击此转到其“属性”选择“Classpath Container”将执行环境更改为java-1.8(jdk1.8.0-35)(最新)

我发现@bigleftie上面的评论很有帮助: “有四件事必须相符

Project->Java Build Path->Libraries->JRE版本 项目->Java编译器->编译器遵从级别 项目- >项目方面- > Java - >版本 (如果使用Maven) pom.xml - Maven -编译器-插件工件的源和目标”。

在我的案例中,在项目属性、Java编译器中,JDK遵从性被设置为使用工作区设置,这与项目的Java版本不同。我点击“Configure Workspace Settings”,并将工作区编译器遵从级别更改为我想要的级别,问题就解决了。

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

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

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

如果您的项目不是Maven项目,右键单击您的项目并选择Properties打开project Properties对话框。

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