Using ANT tasks

Check out the Maven AntRun Plugin, which provides the ability to run Ant tasks within Maven2. This is very handy because it enables to include ant scripts in the your POM (or in an external buld.xml) and therefore customise “ad-hoc” the lifecycle phases.

In the example below I want to deploy (copy) the generated artifact (war) into my local JBoss instance:

<!-- use ANT task -->

<plugin>

   <artifactId>maven-antrun-plugin</artifactId>

      <executions>

         <execution>

            <id>copy-war</id>

            <phase>package</phase>

            <configuration>

               <tasks>

                  <echo>Basedir: ${basedir}</echo>

                  <!-- deploy war to JBoss -->

                  <copy todir="C:/jboss-4.2.0.GA/server/default/deploy">

                     <fileset dir="${basedir}/target">

                        <include name="*.war"></include>

                     </fileset>

                  </copy>

               </tasks>

            </configuration>

            <goals>

               <goal>run</goal>

            </goals>

         </execution>

   </executions>

</plugin>

Pay attention on 2 tags:

  • <execution>: define the script itself and can appear multiple times within the <executions> tag.
  • <phase>: specify which phase of the Maven lifecycle will run the script.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: