Maven对使用JRE感到困惑 [英] Maven confused about JRE been used

查看:26
本文介绍了Maven对使用JRE感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 eclipse 中创建了一个项目并添加了 maven 依赖项.在 Eclipse 中,它说我正在使用 JRE 1.5.在 Eclipse 中一切正常,例如,我可以运行我的测试.

I've created a project in eclipse and added maven dependencies. In Eclipse, it says that I am using JRE 1.5. Everything works fine in Eclipse, for instance, I can run my tests.

当我尝试从终端运行 mvn clean install 时,出现以下错误.

When I try to run mvn clean install from the terminal, it gives me the following error.

...-source 1.3 不支持泛型(使用 -source 5 或更高版本来启用泛型)...

...generics are not supported in -source 1.3 (use -source 5 or higher to enable generics)...

Maven 似乎认为我使用的是 JRE 1.3,无法识别泛型或 for-each 循环.

Its seems that Maven thinks I'm using JRE 1.3 and cannot recognize generics or for-each loops.

我该怎么做:

  • 验证我的假设,即 maven 使用了错误的版本.
  • 让 Maven 编译我的项目.

推荐答案

在 Maven 编译器插件中指定正确的 JRE 版本,默认情况下你的 pom.xml 文件将继承编译器插件来自针对 1.3 JRE 的 Maven 超级 pom.xml.

Specify the correct version of your JRE in the Maven compiler plugin, by default your pom.xml file will inherit the compiler-plugin from the Maven super pom.xml which targets the 1.3 JRE.

     <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>    
        </plugins>
    </build>

这篇关于Maven对使用JRE感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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