如何在pom.xml文件中指定Java编译器版本? [英] How do you specify the Java compiler version in a pom.xml file?
问题描述
我在netbeans上写了一个大约超过2000行的maven代码。当我在netbeans上编译它时,一切都很好,但如果我想在命令行上运行它,我将得到这些错误:
I wrote a maven code on netbeans that has approximately more than 2000 lines. When I compile it on netbeans, everything is fine, but if I want to run it on command line, I will get these errors:
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,编译器错误,但我得到了更多错误。我从其他帖子中发现我应该修改pom.xml,但我不知道怎么做。这是我的pom.xml
I tried to use Java 1.3.1, compiler errors ,but I got more errors. I found from other posts that I should modify pom.xml, but I do not know how. Here is my 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>
如果你可以帮助我会很棒。
It would be great if you can help me.
推荐答案
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>(whatever version is current)</version>
<configuration>
<!-- or whatever version you use -->
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
请参阅maven编译器插件的配置页面:
See the config page for the maven compiler plugin:
http:/ /maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
哦,和:不要使用Java 1.3.x,当前版本是Java 1.7.x或1.8.x
Oh, and: don't use Java 1.3.x, current versions are Java 1.7.x or 1.8.x
这篇关于如何在pom.xml文件中指定Java编译器版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!