NullPointerException 在为 ant build 运行 maven-antrun-plugin 时.x



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

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

=============== Environment =============== 
C:sourceGWTRPCTest>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)Javajdk6_31jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
=============== Log =============== 
C:sourceGWTRPCTest>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:sourceGWTRPCTestsrcmainresources
[INFO] skip non existing resourceDirectory C:sourceGWTRPCTestsrcmainresources
[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:sourceGWTRPCTestbuild
    [mkdir] Created dir: C:sourceGWTRPCTestbuildclasses
    [mkdir] Created dir: C:sourceGWTRPCTestdeploy
bootstrap.maven.tasks:
    [mkdir] Created dir: C:sourceGWTRPCTestbuildlib
      [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:sourceGWTRPCTestbuildlibmaven-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:sourceGWTRPCTestbuildlib
extractLonAssets:
    [unjar] Expanding: c:sourcelon.war into C:sourceGWTRPCTestbuildlon.war.dir
      [jar] Building jar: C:sourceGWTRPCTestbuildibm-web.jar
compile:
    [javac] C:sourceGWTRPCTestbuild.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:sourceGWTRPCTestbuildclasses
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: The following error occurred while executing this line:
C:sourceGWTRPCTestbuild.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 使用的 ant 版本和您系统上的版本可能存在差异。 将以下行添加到将在 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 插件生成源代码。 您需要根据自己的目的自定义阶段等。 希望这有帮助。

最新更新