Maven calling Ant

1

I have a maven project, I want maven to "call" some ant target, I already saw that it has a "maven-antrun-plugin" plugin on the apache website, but I can not understand any examples, someone could give me a simple example, like creating a .jar (I know you can do that in maven) just to know more or less how it works.

    
asked by anonymous 19.10.2015 / 19:52

1 answer

0

Using maven-antrun-plugin you can use an external ant file.

As an example, let's consider this build.xml that contains a target to

<?xml version="1.0"?>
<project name="stack-test">
    <target name="showJavaVersion">
        <exec executable="java">
            <arg value="-version" />
        </exec>
    </target>
</project>

And refer to it in build of our pom.xml as follows:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
                <target>
                    <ant antfile="${basedir}/build.xml">
                        <target name="showJavaVersion" />
                    </ant>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

When we run the life cycle compile ( mvn compile ) we will have an output similar to this:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-antrum-example 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-antrum-example ---
[INFO] skip non existing resourceDirectory /usr/tmp/maven-antrum-example/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-antrum-example ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-antrun-plugin:1.8:run (compile) @ maven-antrum-example ---
[INFO] Executing tasks

main:

showJavaVersion:
     [exec] java version "1.8.0_60"
     [exec] Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
     [exec] Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.228 s
[INFO] Finished at: 2015-10-19T16:49:59-02:00
[INFO] Final Memory: 11M/368M
[INFO] ------------------------------------------------------------------------

Using directly in pom.xml , regardless of build.xml , the equivalent configuration would be this:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
                <target name="showJavaVersion">
                    <exec executable="java">
                        <arg value="-version" />
                    </exec>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
    
19.10.2015 / 20:50