java Maven 对 JRE 的使用感到困惑

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3371737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:33:03  来源:igfitidea点击:

Maven confused about JRE been used

javamavenmaven-2dependencies

提问by Pran

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.

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

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

当我尝试mvn clean install从终端运行时,它给了我以下错误。

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

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

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

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

How can I:

我怎么能够:

  • Validate my assumption that maven is using the wrong version.
  • Get Maven to compile my project.
  • 验证我的假设,即 maven 使用了错误的版本。
  • 让 Maven 编译我的项目。

回答by Jose Diaz

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

在 Maven 编译器插件中指定正确版本的 JRE,默认情况下,您的pom.xml文件将从pom.xml面向 1.3 JRE的 Maven super 继承编译器插件。

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