Maven编译错误
问题内容:
当我在Netbeans中构建并运行程序时,它可以正常工作。但是当我尝试“ mvn compile”时,使用相同的pom.xml文件会出现以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project hadoop-test: Compilation failure
[ERROR] /home/metin/NetBeansProjects/hadoop-test/src/main/java/com/citusdata/hadoop/HadoopTest.java:[53,8] error: generics are not supported in -source 1.3
我的Java版本不是1.3,这里是“ mvn -version”的结果
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_03, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-27-generic", arch: "amd64", family: "unix"
这是第53行:
Token<BlockTokenIdentifier> token = locatedBlock.getBlockToken();
问题答案:
问题是maven-compiler-plugin
在Maven2中默认使用-source 1.3
和target 1.3
您可以通过将其添加到pom中来解决此问题:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerVersion>1.5</compilerVersion>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
将其放在pluginManagement
最顶层的父pom中是很实际的,这样您派生的pom不需要关心此问题。