我在netbeans上写了一个大约超过2000行的maven代码 . 当我在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>
如果你可以帮助我会很棒 .
4 回答
请参阅maven编译器插件的配置页面:
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.
maven-compiler-plugin 它已经存在于pom.xml中的插件层次结构依赖项中 . 检查有效POM .
简而言之,您可以使用以下属性:
我正在使用maven 3.2.5
我在eclipse neon simple maven java项目中遇到了同样的问题
但是我在pom.xml文件中添加了以下细节
右键单击项目> maven>更新项目(已检查强制更新)后
它决定我在项目上显示错误
希望它会有所帮助
Thansk
通常,您不希望仅对
source
版本(例如javac -source 1.8
)进行赋值,但您希望同时对source
和target
版本(例如javac -source 1.8 -target 1.8
)进行赋值 .请注意,从Java 9开始,您可以通过两种方式传递信息,并以更强大的方式进行交叉编译兼容(
javac -release 9
) .包装
javac
命令的Maven提供了多种方式来传达所有这些JVM标准选项 .如何指定JDK版本?
使用
maven-compiler-plugin
或maven.compiler.source
/maven.compiler.target
属性指定source
和target
是等效的 .和
根据Maven documentation of the compiler plugin是等效的,因为编译器配置中的
<source>
和<target>
元素使用属性maven.compiler.source
和maven.compiler.target
(如果已定义) .关于
source
和target
的默认值,请注意since the 3.8.0 of the maven compiler, the default values have changed from 1.5 to 1.6 .从maven-compiler-plugin 3.6中,您有了一种指定Java版本的新方法
你可以使用the release argument:
您还可以声明用户属性
maven.compiler.release
:但是在这个时候最后一个是不够的,因为你使用的
maven-compiler-plugin
默认版本不依赖于最近的版本 .Maven
release
参数传达release
:我们可以从Java 9传递的new JVM standard option:这种方式为
source
,target
和bootstrap
JVM选项提供了标准方法来指定相同的版本 .请注意,指定
bootstrap
是交叉编译的好习惯,如果您不进行交叉编译也不会受到影响 .哪个是指定JDK版本的最佳方法?
For Java 8 and below :
使用
maven-compiler-plugin
的maven.compiler.source
/maven.compiler.target
属性都不是更好 . 它在事实上没有任何改变,因为最终这两种方式依赖于相同的属性和相同的机制:maven核心编译器插件 .好吧,如果您不需要在编译器插件中指定除Java版本之外的其他属性或行为,则使用这种方式更有意义,因为这更简洁:
From Java 9 :
release
参数(第三点)是一种强烈考虑的方法,如果你想为source
和target
使用相同的版本 .