Thomas Sundberg

February 11, 2011

Maven and Antrun

Filed under: Maven, Teaching — Tags: , , — Thomas Sundberg @ 22:32

A friend of mine needed an example of how to use the Antrun Maven plugin.

This is a simple example that will show how to execute any Ant targets from a Maven build during the install phase.


<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>se.sigma.educational.maven.antrun</groupId>
    <artifactId>example</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <id>Hello World</id>
                        <configuration>
                            <target>
                                <!--
                                     Execute any Ant tasks here.
                                     Copy files if you need, echo hello world if
                                     you just want to show a working example.
                                -->
                                <echo>Hello World</echo>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

All we need to to is to set up the Antrun plugin in the build part of the pom.

To tie it to an execution phase, set the execution phase to the life cycle phase you want to execute your ant task in.
In this example I set it to the install phase.

If you want to execute more then one Ant task, then you have to set a unique id for each task.

That’s it folks!

Note that using Antrun is normally not The Maven Way ™
Investigate if you can use other options before you choose to use Antrun.

Resources

About these ads

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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

Customized Silver is the New Black Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 49 other followers

%d bloggers like this: