Maven 编译错误 [英] Maven Compile Error

查看:34
本文介绍了Maven 编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Netbeans 中构建和运行我的程序时,它可以正常工作.但是当我尝试mvn compile"时使用相同的 pom.xml 文件,我收到此错误:

When I build and run my program in Netbeans, it works without a problem. But with same pom.xml file when I try "mvn compile" I get this error:

[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"的结果

My java version is not 1.3, here the result of "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();

推荐答案

问题是Maven2中的maven-compiler-plugin默认使用-source 1.3和<代码>目标 1.3

The problem is that maven-compiler-plugin in Maven2 by default uses -source 1.3 and target 1.3

您可以通过将其添加到您的 pom 中来修复它:

You can fix it by adding this to your 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>

将其放入最顶层父 pom 的 pluginManagement 部分是实用的,这样您的派生 pom 就不需要关心这个了.

It's practical to put this into pluginManagement section in your topmost parent pom so that your derived poms do not need to care about this.

这篇关于Maven 编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆