NullPointerException when running maven-antrun-plugin for an ant build.xml that has javac

1.8k views Asked by At

I am trying to run a build.xml (ant) in my new pom.xml in the same project. However, I always get a NullPointerException no matter what I tried at compile build.xml:104(javac). The build succeeds with ant itself.

Any insights on running build.xml in maven that has a javac target will help!

=============== 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

There are 1 answers

0
Jared On

I'd guess there may be a difference in the version of ant used by maven and the one on your system. Add the following line to the beginning of a target that will be executed in your build.xml file to find out:

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

Then run with both ant and your maven. If they don't match, try downloading the specific version of ant that maven is using and see if you get the same error. If so then you know this is the problem.

Update

I was able to work around this problem when I had it. You can tell the maven-antrun-plugin to use a more recent version of ant as its dependency, instead of the one it uses by default. For instance, I was able to get my antrun code to work with version 1.9.3, but it didn't with the default version of 1.8.2, so I used this code:

<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>

As you can see, I was generating source code with the antrun plugin. You will need to customize the phase, etc. for your own purposes. Hope this helps.