Maven对使用JRE感到困惑

2023-07-14Java开发问题
1

本文介绍了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感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13