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/16723533/

相关文章:

maven - OpenCV-2.4.4 POM入门标签

java - 系统找不到指定的路径(MANIFEST.MF)

如果修改了包含的元素,则 Java HashSet 包含重复项

java - 为使用 JSch 通过 SSH 执行的命令提供输入/子命令

java - 如何将 DateFormat 与字符串数组进行比较

java - 每次打开终端时 Apache Maven 都会重置

java - 使用 Java 14 的 IntelliJ 2020.1 中的 "Records"预览功能在 Maven `install` 期间因编译器错误而失败,但以其他方式运行

Eclipse 挂起恢复资源

java - 将事件从 child 传递给 parent

maven - 如何知道pom.xml中定义的value变量?