【问题标题】:Execute Ant task with Maven使用 Maven 执行 Ant 任务
【发布时间】:2011-02-07 02:15:31
【问题描述】:

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

我的 POM 是这样定义的:

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

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

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

但是,如果我运行:“mvn antrun:run”,我知道这不能运行任务。

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

谢谢。

贡萨洛

【问题讨论】:

    标签: maven-2 ant task


    【解决方案1】:

    要在 Maven 2 中运行 Ant 任务,您需要使用 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 生成构建文件。

    【讨论】:

      【解决方案2】:

      试试这个..这将处于验证阶段。

             <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-antrun-plugin</artifactId>
                      <version>1.1</version>
                      <executions>
                          <execution>
                              <phase>validate</phase>
                              <goals>
                                  <goal>run</goal>
                              </goals>
                              <configuration>
                                  <tasks>
      
                                      <echo message="Hello world" />
                                      <echo message="${env.M2_HOME}" ></echo>
      
                                  </tasks>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
      

      【讨论】:

        猜你喜欢
        • 2016-09-16
        • 2011-03-20
        • 2014-02-14
        • 2011-03-31
        • 1970-01-01
        • 2013-06-19
        • 2017-12-18
        • 2011-04-23
        • 1970-01-01
        相关资源
        最近更新 更多