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

发布于 2024-12-09 05:19:40 字数 358 浏览 1 评论 0原文

我在 Eclipse Helios 版本下创建了一个新的动态项目,其中我的 JRE 版本设置为 1.6。 我已通过单击“配置”→“转换为 Maven 项目”将 Maven 功能添加到 Web 应用程序。

添加此内容后,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)。

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.

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

你的心境我的脸 2024-12-16 05:19:40

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

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

项目事实 - Java版本

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

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 Factes - Java version

暖风昔人 2024-12-16 05:19:40

假设您在 Eclipse 中使用 m2e 插件,则需要将 maven-compiler-pluginsourcetarget 版本指定为 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>

或者,您可以指定值为 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>

Assuming that you are using the m2e plugin in Eclipse, you'll need to specify the source and target versions 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:

<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.source and maven.compiler.target properties with values of 1.6, that happen to be the equivalent:

<properties>
    <maven.compiler.target>1.6</maven.compiler.target>
    <maven.compiler.source>1.6</maven.compiler.source>
</properties>
荭秂 2024-12-16 05:19:40

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

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.

月隐月明月朦胧 2024-12-16 05:19:40

我发现@bigleftie 上面的评论非常有帮助:
“有四件事必须匹配

  1. 项目 -> Java 构建路径 -> 库 -> JRE 版本
  2. 项目 -> Java 编译器 -> 编译器合规性级别
  3. 项目 -> 项目 Facets -> Java -> 版本
  4. (如果使用Maven) pom.xml - maven-compiler-plugin artefact 源和目标”。

就我而言,在项目属性、Java 编译器、JDK 合规性中设置为使用工作区设置,这与项目的 java 版本不同。我单击“配置工作区设置”,并将工作区编译器合规性级别更改为我想要的,问题得到解决。

I found @bigleftie's comment above very helpful:
"Four things must match

  1. Project->Java Build Path->Libraries->JRE version
  2. Project->Java Compiler-> Compiler Compliance Level
  3. Project->Project Facets->Java->Version
  4. (if using Maven) pom.xml - maven-compiler-plugin artefact source and target".

In my case, in the project properties, Java compiler, the JDK compliance was set to use the workspace settings, which were different from the java version for the project. I clicked on 'Configure Workspace Settings', and changed the workspace Compiler compliance level to what I wanted, and the problem was resolved.

悲欢浪云 2024-12-16 05:19:40

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

供参考 -

在此输入图像描述

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.

For reference -

enter image description here

我通过 Myproject--->java Resource---->libraries-->JRE System 解决了它库[java-1.6] 单击此转到其“属性”,选择“类路径容器”执行环境更改为java-1.8(jdk1.8.0-35)(即最新

将jdk更改为最新

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 Environment to java-1.8(jdk1.8.0-35) (that is latest)

Change the jdk to latest

赢得她心 2024-12-16 05:19:40

我将 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 中删除项目。
这对我有用。

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

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.

若能看破又如何 2024-12-16 05:19:40

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

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

以为你会在 2024-12-16 05:19:40

您可以更改项目方面
项目-->属性-->项目方面--> Java --> {所需的JDK版本}

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

傾旎 2024-12-16 05:19:40

右键单击项目并选择属性
点击左边的java编译器,改成你需要的版本
希望这有帮助

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

森林散布 2024-12-16 05:19:40

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

在此处输入图像描述

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.

enter image description here

醉生梦死 2024-12-16 05:19:40

如果使用eclipse,

在settings下点击org.eclipse.wst.common.project.facet.core.xml

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <installed facet="java" version="1.7"/>
</faceted-project>

将版本更改为正确的版本。

If using eclipse,

Under.settings click on org.eclipse.wst.common.project.facet.core.xml

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <installed facet="java" version="1.7"/>
</faceted-project>

Change the version to the correct version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文