问题描述
我导入了一个 Maven 项目并且它使用了 Java 1.5,即使我将 1.6 配置为我的 Eclipse 默认Preferences->Java->Installed JREs
.
I imported a Maven project and it used Java 1.5 even though I have 1.6 configured as my Eclipse default Preferences->Java->Installed JREs
.
当我将 Maven 项目更改为使用 1.6 JRE 时,它仍然存在项目使用 Java 1.5 时遗留的构建错误(我在前面描述了这些构建错误:我在 m2eclipse 上有构建错误,但在 maven2 上没有命令行 - 我的 m2eclipse 配置错误吗?)
When I changed the Maven project to use the 1.6 JRE it still had the build errors left over from when the project was using Java 1.5 (I described these build errors earlier in: I have build errors with m2eclipse but not with maven2 on the command line - is my m2eclipse misconfigured?)
我将删除该项目并重试,但这次我想确保它从一开始就使用 Java 1.6,看看这是否消除了构建问题.
I'm going to delete the project and try again but I want to make sure this time that it uses Java 1.6 from the start to see if this eliminates the build problems.
导入时如何确保项目使用 Java 1.6?
How do I make sure the project uses Java 1.6 when I import it?
推荐答案
m2eclipse 插件不使用 Eclipse 默认设置,m2eclipse 插件从 POM 派生设置.因此,如果您希望在 Eclipse 下导入时将 Maven 项目配置为使用 Java 1.6 设置,请适当配置 maven-compiler-plugin
,正如我已经建议的:
The m2eclipse plugin doesn't use Eclipse defaults, the m2eclipse plugin derives the settings from the POM. So if you want a Maven project to be configured to use Java 1.6 settings when imported under Eclipse, configure the maven-compiler-plugin
appropriately, as I already suggested:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
如果您的项目已导入,请更新项目配置(右键单击项目,然后Maven V 更新项目配置).
If your project is already imported, update the project configuration (right-click on the project then Maven V Update Project Configuration).
这篇关于是什么导致 Eclipse 中导入的 Maven 项目默认使用 Java 1.5 而不是 Java 1.6,我如何确保它不会?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!