Usage

Run

The maven-antrun-plugin has only one goal, run.

This allows maven 2 to run ant tasks. To do so, there must be an existing project and the maven-antrun-plugin must have its <tasks> tag configured (although it would still execute without the <tasks> tag, it would not do anything). Below is the template for the maven-antrun-plugin's pom.xml.

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase> <!-- a lifecycle phase --> </phase>
            <configuration>
              <tasks>

                <!--
                  Place any ant task here. You can add anything
                  you can add between <target> and </target> in a
                  build.xml.
                -->
                
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Moreover, you can add a script to each lifecycle phase, by duplicating the <execution/> section and specifying a new phase.

Below you can see how to indicate that ant has generated some more java source that needs to be included in the compilation phase. Note that the compile phase follows the generate-sources phase in the lifecycle.

<project>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>my-test-app</artifactId>
  <groupId>my-test-group</groupId>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <configuration>
              <tasks>

                <!--
                  Place any ant task here. You can add anything
                  you can add between <target> and </target> in a
                  build.xml.
                -->

              </tasks>
              <sourceRoot>${project.build.directory}/generated-sources/main/java</sourceRoot>
              <testSourceRoot>${project.build.directory}/generated-sources/test/java</testSourceRoot>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
</project>

Of course, you can put whatever folder you prefer. The folders in the example above arehandy because they are deleted when you clean since they are in the build directory (which is, by default, "target").

<sourceRoot/> adds a single folder to the list of folders that get compiled with the program source code (compile).

<testSourceRoot/> adds a single folder to the list of folders that get compiled with the test source code (test-compile).

Ant Expressions to Maven Expressions Mapping

Some Ant expressions have their respective counterparts in Maven. Thus, one can simply invoke the corresponding maven expression instead of using maven-antrun-plugin to avoid the unneccessary overhead.

Ant ExpressionMaven Expression
Built-in Tasks
Antmaven-antrun-plugin
AntCallmaven-antrun-plugin
Availableprofiles
BUnzip2maven-assembly-plugin
BZip2maven-assembly-plugin
Chmodmaven-assembly-plugin
Conditionprofiles
Copymaven-resources-plugin
Dependsetmaven-dependency-plugin
Earmaven-ear-plugin
Filtermaven-resources-plugin
Note: Filter uses the @...@ token while maven-resources-plugin uses the ${...} token
FixCRLFmaven-resources-plugin
GenKeymaven-jar-plugin
GUnzipmaven-assembly-plugin
GZipmaven-assembly-plugin
Jarmaven-jar-plugin
Javacmaven-compiler-plugin
Javadoc/Javadoc2maven-javadoc-plugin
LoadPropertiesmaven-resources-plugin
Manifestmaven-jar-plugin
Propertymaven-resources-plugin
Replacemaven-resources-plugin
Note: Replace can specify its token while maven-resources-plugin uses the ${...} token
Tarmaven-assembly-plugin
Unjarmaven-assembly-plugin
Untarmaven-assembly-plugin
Unwarmaven-assembly-plugin
Unzipmaven-assembly-plugin
Warmaven-war-plugin
Zipmaven-assembly-plugin
Optional Tasks
Antlrmaven-antlr-plugin
Dependmaven-dependency-plugin
EJB Tasksmaven-ejb-plugin
FTPmaven-deploy-plugin
Note: maven-deploy-plugin can only deploy unto the FTP
JavaCCmaven-compiler-plugin
JJDocmaven-compiler-plugin
JJTreemaven-compiler-plugin
JUnitmaven-surefire-plugin
JUnitReportmaven-surefire-report-plugin
ServerDeploymaven-deploy-plugin
Setproxymaven-deploy-plugin
Translatemaven-resources-plugin
Note: Translate can specify its own tokens and can have a different encoding scheme for reading and writing files. maven-resources-plugin however uses the ${...} annotation only and has only one encoding scheme for reading and writing