Guide to using Ant with Maven

The example above illustrates how to bind an ant script to a lifecycle phase. You can add a script to each lifecycle phase, by duplicating the execution/ section and specifying a new phase.

  1. <project>
  2. <modelVersion>4.0.0</modelVersion>
  3. <artifactId>my-test-app</artifactId>
  4. <groupId>my-test-group</groupId>
  5. <version>1.0-SNAPSHOT</version>
  6. <build>
  7. <plugins>
  8. <plugin>
  9. <artifactId>maven-antrun-plugin</artifactId>
  10. <version>1.7</version>
  11. <executions>
  12. <execution>
  13. <phase>generate-sources</phase>
  14. <configuration>
  15. <tasks>
  16.  
  17. <!--
  18. Place any ant task here. You can add anything
  19. you can add between <target> and </target> in a
  20. build.xml.
  21. -->
  22.  
  23. </tasks>
  24. </configuration>
  25. <goals>
  26. <goal>run</goal>
  27. </goals>
  28. </execution>
  29. </executions>
  30. </plugin>
  31. </plugins>
  32. </build>
  33. </project>

So a concrete example would be something like the following:

  1. <project>
  2. <modelVersion>4.0.0</modelVersion>
  3. <artifactId>my-test-app</artifactId>
  4. <groupId>my-test-group</groupId>
  5. <version>1.0-SNAPSHOT</version>
  6. <build>
  7. <plugins>
  8. <plugin>
  9. <artifactId>maven-antrun-plugin</artifactId>
  10. <version>1.7</version>
  11. <executions>
  12. <execution>
  13. <phase>generate-sources</phase>
  14. <configuration>
  15. <tasks>
  16. <exec
  17. dir="${project.basedir}"
  18. executable="${project.basedir}/src/main/sh/do-something.sh"
  19. failonerror="true">
  20. <arg line="arg1 arg2 arg3 arg4" />
  21. </exec>
  22. </tasks>
  23. </configuration>
  24. <goals>
  25. <goal>run</goal>
  26. </goals>
  27. </execution>
  28. </executions>
  29. </plugin>
  30. </plugins>
  31. </build>
  32. </project>