使用 Maven 执行 Ant 任务 [英] Execute Ant task with Maven

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

问题描述

我正在尝试使用 Maven 执行一些使用 Ant 任务编写的测试.我生成了将任务导入 Maven 所需的文件,但我无法执行它们.

I'm trying to execute with Maven some test written using Ant tasks. I generated the files required to import the task into Maven, but I can't execute them.

我的 POM 是这样定义的:

My POM is defined this way:

<build>
  <plugins>
      <plugin>
        <artifactId>maven-ant-plugin</artifactId>
        <version>2.1</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <configuration>
              <tasks>
                <echo message="Hello, maven"/>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

我尝试执行该消息,但运行时出现错误:

I try to execute that message, but I get an error with run:

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] 'run' was specified in an execution, but not found in the plugin

但是,如果我运行:"mvn antrun:run",我知道这不能运行任务.

But, if I run: "mvn antrun:run", I know that this can not run the task.

如果我有不同的目标,我如何从 Maven 调用它们?我有 pom.xml 和带有 ant 任务的 build.xml.

An if I've different targets, how do I call them from Maven? I've the pom.xml, and build.xml with the ant tasks.

谢谢.

贡萨洛

推荐答案

要从 Maven 2 中运行 Ant 任务,您需要使用 Maven AntRun 插件:

To run Ant tasks from within Maven 2, you need to use the Maven AntRun Plugin:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.3</version>
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <configuration>
            <tasks>
              <echo message="Hello, maven"/>
            </tasks>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Maven Ant Plugin 是另外一回事,它是用于从 POM 为 Ant 生成构建文件.

The Maven Ant Plugin is something else, it is used to generate build files for Ant from the POM.

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

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