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.
我希望它可以帮助面临项目方面问题的人。