什么导致Eclipse中的新的Maven项目默认使用Java 1.5而不是Java 1.6,如何确保它不? [英] What causes a new Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't?

查看:148
本文介绍了什么导致Eclipse中的新的Maven项目默认使用Java 1.5而不是Java 1.6,如何确保它不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我导入了一个Maven项目,它使用了Java 1.5,尽管我将1.6配置为我的Eclipse默认值 Preferences-> Java-> Installed JREs



当我将Maven项目更改为使用1.6 JRE时,它仍然有从项目使用Java 1.5时遗留的构建错误(我在之前描述了这些构建错误:我在m2eclipse中构建了错误,但是在命令行上没有使用maven2 - 是我的m2eclipse配置错误吗?



我将删除项目,再试一次,但我想确保这一次它从一开始就使用Java 1.6,看看是否消除了构建问题。



如何确保项目使用Java 1.6当我导入它时

解决方案

m2eclipse插件不使用Eclipse默认值,m2eclipse插件从POM。因此,如果您希望将Maven项目配置为在Eclipse下导入时使用Java 1.6设置,请按照我已经建议的方式正确配置 maven-compiler-plugin

 < 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更新项目配置)。


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.

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

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.

How do I make sure the project uses Java 1.6 when I import it?

解决方案

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>

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,如何确保它不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆