MTT*_*MTT 249 java pom.xml maven
我在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
Run Code Online (Sandbox Code Playgroud)
我试图使用Java 1.3.1,编译器错误,但我得到了更多的错误.我从其他帖子中发现我应该修改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>
Run Code Online (Sandbox Code Playgroud)
如果你可以帮助我会很棒.
leo*_*ges 350
maven-compiler-plugin它已经存在于pom.xml中的插件层次结构依赖项中.入住有效的POM.
简而言之,您可以使用以下属性:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
我正在使用maven 3.2.5
Sea*_*oyd 302
<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>
Run Code Online (Sandbox Code Playgroud)
请参阅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.
dav*_*xxx 12
通常,您不希望仅对source版本进行值(javac -source 1.8例如),但您希望同时对值source和target版本进行值(javac -source 1.8 -target 1.8例如).
请注意,从Java 9开始,您可以通过两种方式传递信息,并以更强大的方式进行交叉编译兼容性(javac -release 9).
包装javac命令的Maven 提供了多种方式来传达所有这些JVM标准选项.
使用maven-compiler-pluginor maven.compiler.source/ maven.compiler.targetproperties指定source和target等效.
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
和
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
根据编译器插件的Maven文档是等价的,
因为编译器配置中<source>的<target>元素和属性maven.compiler.source以及maven.compiler.target它们是否已定义.
-sourceJava编译器的参数.
默认值为:1.6.
用户属性是:maven.compiler.source.
-targetJava编译器的参数.
默认值为:1.6.
用户属性是:maven.compiler.target.
关于默认值source,并 target请注意,
由于3.8.0Maven的编译器,默认值已经从改变1.5到1.6.
您可以使用的release参数 :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>9</release>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
您还可以声明用户属性maven.compiler.release:
<properties>
<maven.compiler.release>9</maven.compiler.release>
</properties>
Run Code Online (Sandbox Code Playgroud)
但是目前最后一个maven-compiler-plugin版本还不够,因为您使用的默认版本不依赖于最近的版本.
Maven release参数传达release:我们可以从Java 9 传递 的新JVM标准选项:
针对特定VM版本的公共,支持和记录的API进行编译.
通过这种方式提供一种标准方法来指定相同的版本source,在target和bootstrapJVM选项.
请注意,指定bootstrap对于交叉编译是一种很好的做法,如果您不进行交叉编译也不会受到影响.
对于Java 8及更低版本:
没有maven.compiler.source/ maven.compiler.target属性或使用maven-compiler-plugin更好.它在事实上没有任何改变,因为最终这两种方式依赖于相同的属性和相同的机制:maven核心编译器插件.
好吧,如果您不需要在编译器插件中指定除Java版本之外的其他属性或行为,则使用这种方式更有意义,因为这更简洁:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
从Java 9开始:
该release参数(第三点),如果你想使用相同版本的强烈考虑的方式source和target.
小智 10
我在eclipse neon simple maven java项目中遇到了同样的问题
但是我在pom.xml文件中添加了以下细节
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
右键单击项目> maven>更新项目(已检查强制更新)后
它决定我在项目上显示错误
希望它会有所帮助
Thansk