How do I call Ant Builts using Maven

2019-07-22 02:38发布

问题:

I have many sub modules of php projects which are run using ANT [It just copies files and runs SQL].

Now I need to Implement Maven for handling future Unit Testing + [Maven is the Best tool which we anyway need to use in the future.]

I have installed Maven for php in Eclipse. I have made a new project using Maven in the IDE itself. I can run the Project also. [I am a noob to Maven but good with ANTs]

Now I want to call those submodular ANT's xml using the Maven project. There is ANT RUN which does the trick for maven, but I am not able to:

  • figure out how to reference modules' ANT xml outside the Maven Project.
  • Ant just merely linking the XML would do the job? Or do I need more dependencies?

回答1:

Use the Maven ant runner plugin to invoke the ANT logic, using ANT's subant task

Example

$ tree
.
|-- pom.xml
`-- src
    `-- main
        `-- ant
            |-- module1
            |   `-- build.xml
            `-- module2
                `-- build.xml

5 directories, 3 files

pom.xml

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myspotontheweb.demo</groupId>
    <artifactId>demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <configuration>
                            <target>
                                <property name="src.dir" location="${project.build.directory}/../src"/>
                                <subant>
                                    <fileset dir="${src.dir}" includes="**/build.xml"/>
                                </subant>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

ANT is configured to run during the "compile" phase of the Maven build. The ANT logic uses the subant task to run external ANT logic.

Run example

$ mvn compile
..    
..
[INFO] --- maven-antrun-plugin:1.7:run (default) @ demo ---
[INFO] Executing tasks

main:

main:
     [echo] module1: hello world

main:
     [echo] module2: hello world
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.394s
[INFO] Finished at: Fri Apr 27 20:25:35 IST 2012
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------


回答2:

You can simply use ant task inside target configuration element of Maven's Ant Run plugin.



标签: php maven ant