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

标签 java maven pom.xml

我在 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/

相关文章:

java - vector 似乎不包含正确的数据

java - 如何获取 Drools 中 Activity 规则的数量?

java - 当使用 "bundle"打包时,maven-bundle-plugin 目标被执行两次

maven-2 - Maven 耳朵插件没有选择 application.xml

java - Maven依赖的依赖关系

java - 无法在 Weatherlib API android 上检索搜索到的城市

java - archetypeArtifactId 的用途是什么?

maven-dependency-plugin unpack-dependencies 不支持包含超过 100 个字符的路径的 tar

java - 无法为 serenity+jbehave 配置 pom.xml

java - Selenium Webdriver 和 Selenium Ghostdriver 有什么区别?