gpt4 book ai didi

java - 如何在 pom.xml 文件中指定 Java 编译器版本?

转载 作者:行者123 更新时间:2023-12-02 02:53:44 25 4
gpt4 key购买 nike

我在 Netbeans 中编写了一些 Maven 代码,大约有 2000 多行。当我在 Netbeans 上编译它时,一切都很好,但如果我想在命令行上运行它,我会收到以下错误:

generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();

generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
HashSet<Double> resid_List = new HashSet<Double>(Arrays.asList(resid_val));

generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
List<Integer> ind_ovlpList = new ArrayList<Integer>(Arrays.asList(ind_ovlp));

generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
public class ColumnComparator implements Comparator<double[]> {

annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@Override

我尝试使用 Java 1.3.1, compiler errors ,但我遇到了更多错误。我从其他帖子中发现我应该修改 pom.xml,但我不知道如何修改。这是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<artifactId>mavenmain</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mavenmain</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>gov.nist.math</groupId>
<artifactId>jama</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
</project>

如果你能帮助我,那就太好了!

最佳答案

ma​​ven-compiler-plugin 它已经存在于 pom.xml 中的插件层次结构依赖项中。 checkin 有效的 POM。

简而言之,您可以使用如下属性:

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

我使用的是 Maven 3.2.5。

关于java - 如何在 pom.xml 文件中指定 Java 编译器版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57091496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com