为具有javac的ant build.xml运行maven-antrun-plugin时出现NullPointerException

时间:2013-09-09 13:23:23

标签: maven nullpointerexception pom.xml maven-antrun-plugin

我正在尝试在同一项目中的新pom.xml中运行build.xml(ant)。但是,无论我在编译build.xml:104(javac)时尝试过什么,我总是得到一个NullPointerException。构建成功与ant本身。

有关在具有javac目标的maven中运行build.xml的任何见解都会有所帮助!

=============== Environment =============== 

C:\source\GWTRPCTest>mvn -version
Listening for transport dt_socket at address: 5005
Apache Maven 2.2.1 (r801777; 2009-08-06 14:16:01-0500)
Java version: 1.6.0_31
Java home: c:\Program Files (x86)\Java\jdk6_31\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"

=============== Log =============== 

C:\source\GWTRPCTest>mvn package
Listening for transport dt_socket at address: 5005
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO]    task-segment: [package]
[INFO] ------------------------------------------------------------------------
[INFO] [version:setversion {execution: version}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\source\GWTRPCTest\src\main\resources
[INFO] skip non existing resourceDirectory C:\source\GWTRPCTest\src\main\resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] No sources to compile
[INFO] [antrun:run {execution: generate-sources}]
[INFO] Executing tasks

init:
    [mkdir] Created dir: C:\source\GWTRPCTest\build
    [mkdir] Created dir: C:\source\GWTRPCTest\build\classes
    [mkdir] Created dir: C:\source\GWTRPCTest\deploy

bootstrap.maven.tasks:
    [mkdir] Created dir: C:\source\GWTRPCTest\build\lib
      [get] Getting: http://artifactory.bpm.ibm.com:8081/artifactory/simple/ext-release-local/org/apache/maven/maven-artifact-ant/2.1.0/maven-artifact-ant-2.1.0.jar
      [get] To: C:\source\GWTRPCTest\build\lib\maven-ant-tasks-2.1.0.jar

init.maven.tasks:

prepare:
     [echo]
     [echo] *** The file c:/source/lon.war should be from a non-development build...
     [echo]
     [copy] Copying 5 files to C:\source\GWTRPCTest\build\lib

extractLonAssets:
    [unjar] Expanding: c:\source\lon.war into C:\source\GWTRPCTest\build\lon.war.dir
      [jar] Building jar: C:\source\GWTRPCTest\build\ibm-web.jar

compile:
    [javac] C:\source\GWTRPCTest\build.xml:104: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 5 source files to C:\source\GWTRPCTest\build\classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: The following error occurred while executing this line:
C:\source\GWTRPCTest\build.xml:104: java.lang.NullPointerException

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 minutes 22 seconds
[INFO] Finished at: Fri Sep 06 10:53:59 CDT 2013
[INFO] Final Memory: 46M/618M
[INFO] ------------------------------------------------------------------------

1 个答案:

答案 0 :(得分:0)

我猜想maven和你系统上使用的蚂蚁版本可能有所不同。将以下行添加到将在build.xml文件中执行的目标的开头,以查找:

<echo message="Ant version is: ${ant.version}"/>

然后用蚂蚁和你的母亲一起跑。如果它们不匹配,请尝试下载maven正在使用的特定版本的ant,看看是否收到相同的错误。如果是这样,那你就知道这就是问题所在。

<强>更新

当我拥有它时,我能够解决这个问题。您可以告诉maven-antrun-plugin使用更新版本的ant作为其依赖项,而不是默认情况下使用的版本。例如,我能够使用我的antrun代码使用版本1.9.3,但它没有使用默认版本1.8.2,所以我使用了这段代码:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>generateSources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <echo message="Ant version for antrun is ${ant.version}"/>
                    <!-- Other ant stuff here-->
                </target>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <!--The default version of ant used for antrun (1.8.2) causes above to
        hit a NullPointerException.  Ant 1.9.3 doesn't have this issue. -->
        <dependency>
          <groupId>org.apache.ant</groupId>
          <artifactId>ant</artifactId>
          <version>1.9.3</version>
        </dependency>
    </dependencies>
</plugin>

正如您所看到的,我使用antrun插件生成源代码。您需要根据自己的需要自定义阶段等。希望这可以帮助。