【问题标题】:NullPointerException when running maven-antrun-plugin for an ant build.xml that has javac为具有 javac 的 ant build.xml 运行 maven-antrun-plugin 时出现 NullPointerException
【发布时间】:2013-09-09 13:23:22
【问题描述】:

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

任何有关在具有 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] ------------------------------------------------------------------------

【问题讨论】:

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


    【解决方案1】:

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

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

    然后用 ant 和你的 maven 运行。如果它们不匹配,请尝试下载 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 插件生成源代码。您将需要根据自己的目的自定义阶段等。希望这可以帮助。

    【讨论】:

      猜你喜欢
      • 2011-06-06
      • 2010-11-22
      • 2019-09-06
      • 1970-01-01
      • 1970-01-01
      • 2015-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多