2010-04-12 85 views
6

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

我的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:运行“,我知道这不能运行任务。

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

谢谢。

贡萨洛

回答

12

从内部的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是别的东西,它是用来生成构建文件为Ant从POM 。

+0

是的,我没弄明白,谢谢。 – Gonzalo 2010-04-12 17:25:40

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> 
相关问题