Configure the run goal of the Maven AntRun plugin to execute an inline Ant script. The POM shown in configures the run goal to execute during the prepare-package phase of the build. The Ant script is contained in the tasks configuration parameter for the ant-magic execution.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mhandbook</groupId>
<artifactId>ant-script</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ant-script</name>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ant-magic</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<property name="compile_classpath"
refid="maven.compile.classpath"/>
<echo file="${project.build.outputDirectory}/deps.txt"
message="compile classpath: ${compile_classpath}"/>
<copy todir="${project.build.outputDirectory}">
<fileset dir="${project.build.sourceDirectory}"/>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>You can run this script, by executing the package phase.
~/examples/ant/ant-script $ mvn package
[INFO] Scanning for projects...
...
[INFO] [antrun:run {execution: ant-magic}]
[INFO] Executing tasks
[copy] Copying 1 file to ~/examples/ant/ant-script/target/classes
[INFO] Executed tasks
...
[INFO] BUILD SUCCESSFULOnce this simple Ant script has been completed, the contents of ${basedir}/target/classes/deps.txt should contain the following:
compile classpath: ~/examples/ant/ant-script/target/classes
Written by Maven creator Jason Van Zyl and his team at Sonatype, Maven: The Definitive Guide clearly explains how this popular tool can bring order to your software development projects. The first part of the book demonstrates Maven's capabilities through the development of several sample applications from ideation to deployment, and the second part offers a complete reference guide. Concise and to the point, this is the only guide you need to manage your project.




Help









