我如何使用 Maven 调用 Ant Builts [英] How do I call Ant Builts using Maven

查看:26
本文介绍了我如何使用 Maven 调用 Ant Builts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多使用 ANT 运行的 php 项目子模块 [它只是复制文件并运行 SQL].

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

现在我需要实现 Maven 以处理未来的单元测试 + [Maven 是我们将来无论如何需要使用的最佳工具.]

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.]

我已经在 Eclipse 中为 php 安装了 Maven.我在 IDE 本身中使用 Maven 创建了一个新项目.我也可以运行该项目.[我是 Maven 的菜鸟,但很擅长 ANTs]

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]

现在我想使用 Maven 项目调用那些子模块 ANT 的 xml.有 ANT RUN 可以解决 maven 的问题,但我不能到:

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:

  • 弄清楚如何在 Maven 项目之外引用模块的 ANT xml.
  • Ant 仅仅链接 XML 就可以完成这项工作吗?还是我需要更多依赖?

推荐答案

使用 Maven ant runner 插件调用ANT逻辑,使用ANT的subant任务

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

$ 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 被配置为在 Maven 构建的编译"阶段运行.ANT 逻辑使用 subant 任务来运行外部 ANT 逻辑.

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.

$ 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] ------------------------------------------------------------------------

这篇关于我如何使用 Maven 调用 Ant Builts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆