[修复] Eclipse – Java编译器级别与已安装的Java项目构面的版本不匹配

在Eclipse中导入Maven项目后,更改Java编译器级别为1.7,但遇到'Java编译器级别与已安装的Java项目构面版本不匹配'的错误。解决方法是通过修改项目属性,将Java Project Facet版本从1.5更新到1.7。此外,也可通过编辑项目根目录的.settings文件来完成设置。若想在终端中更改编译器合规性级别,需编辑.project文件的相关属性。
摘要由CSDN通过智能技术生成

Recently I imported a Maven project in Eclipse and changed the build path Library to work on Java 1.7. After that Eclipse shown me error in project, although there was no error shown in any files.

最近,我在Eclipse中导入了一个Maven项目,并更改了构建路径库以在Java 1.7上运行。 之后,Eclipse在项目中向我显示了错误,尽管在任何文件中均未显示任何错误。

Java编译器级别与已安装的Java项目构面的版本不匹配 (Java compiler level does not match the version of the installed Java project facet)

The error description was Java compiler level does not match the version of the installed Java project facet.

错误说明是Java compiler level does not match the version of the installed Java project facet.

I also changed the project compiler compliance level to 1.7 but still error was not gone. Below screenshot shows the Problem View where this error was shown.

我还将项目编译器的合规性级别更改为1.7,但仍然没有出错。 下面的屏幕截图显示了显示此错误的问题视图。

Java编译器级别的修复与安装的Java项目构面的版本不匹配 (Fix for Java compiler level does not match the version of the installed Java project facet)

After some research and looking at the project properties, I was able to fix this issue. All I needed to do was to change the Java Project Facet version from 1.5 to 1.7.

经过一些研究并查看了项目的属性,我能够解决此问题。 我要做的就是将Java Project Facet版本从1.5更改为1.7。

Below screenshot shows the Project properties window where you can set the project facets version.

下面的屏幕截图显示了“项目属性”窗口,您可以在其中设置项目构面版本。

Personally I don’t like to change anything in UI, I am more inclined to do things through terminal.

我个人不喜欢在UI中进行任何更改,我更倾向于通过终端来执行操作。

Well, there is a way to do this by editing the project settings for facets.

嗯,有一种方法可以通过编辑构面的项目设置来实现。

You will find this in org.eclipse.wst.common.project.facet.core.xml file inside .settings folder at the project root.

您可以在项目根目录.settings文件夹内的org.eclipse.wst.common.project.facet.core.xml文件中找到此文件。

The original content of this file was:

该文件的原始内容为:

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="jst.web" version="2.3"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
  <installed facet="java" version="1.5"/>
</faceted-project>

I modified it to below.

我将其修改为以下内容。

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="jst.web" version="2.3"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
  <installed facet="java" version="1.7"/>
</faceted-project>

After refreshing the project, error was gone.

刷新项目后,错误消失了。

Java编译器级别的奖金提示与已安装的Java项目构面的版本不匹配 (Bonus Tip for Java compiler level does not match the version of the installed Java project facet)

If you want to change the compiler compliance level from terminal, you need to edit below properties in org.eclipse.jdt.core.prefs file.

如果要从终端更改编译器合规性级别,则需要在org.eclipse.jdt.core.prefs文件中编辑以下属性。

org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.source=1.7

We can change the Library also in .classpath file of the project, but that is not easy and it depends on the name configured for the Library, for example in my project classpath file, entry for JRE looks like below.

我们也可以在项目的.classpath文件中更改Library,但这并不容易,并且取决于为Library配置的名称,例如在我的项目classpath文件中,JRE的条目如下所示。

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Home">
	<attributes>
		<attribute name="owner.project.facets" value="java"/>
	</attributes>
</classpathentry>

I hope it will help someone facing this issue with project facets.

我希望它可以帮助面临项目方面问题的人。

翻译自: https://www.journaldev.com/3334/eclipse-java-compiler-level-does-not-match-the-version-of-the-installed-java-project-facet

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值