2010-05-12 76 views
12

使用Maven可以执行build.xml脚本吗?使用Maven执行build.xml

这个脚本checksout我所有的项目和子项目和我只是习惯了使用maven,并没有真正使用之前很多蚂蚁,我知道蚂蚁能与Maven使用。所以我的问题是:如何?

回答

7

我真的不是这种方法的大风扇(或者使用Ant,或Maven,但不是混蛋混合),但你可以使用一个外部build.xmlMaven AntRun Plugin

<project> 
    ... 
    <build> 
    <plugins> 
     ... 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <configuration> 
      <tasks> 
      <taskdef resource="net/sf/antcontrib/antcontrib.properties" 
       classpathref="maven.plugin.classpath" /> 
      <ant antfile="${basedir}/build.xml"> 
       <target name="test"/> 
      </ant> 
      </tasks> 
     </configuration> 
     <dependencies> 
      <dependency> 
      <groupId>ant-contrib</groupId> 
      <artifactId>ant-contrib</artifactId> 
      <version>1.0b3</version> 
      </dependency> 
     </dependencies> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

然后运行mvn antrun:run(或者如果要将AntRun插件绑定到生命周期阶段,请将配置放入execution,请参阅Usage页面)。

更新:如果您使用ant-contrib中的东西,则需要将其声明为插件的依赖关系。我更新了插件配置以反映这一点。另请注意我添加的taskdef元素(我不确定您是否需要classpathref属性)。

+0

$ {basedir}是pom.xml旁边的哪个位置?要么 ? – 2010-05-12 10:13:26

+0

@Gandalf是,'$ {BASEDIR}'代表包含pom.xml的 – 2010-05-12 10:34:29

+0

这个我试过使用V1.7的antrun插件的目录,似乎我们的目标是现在运行e.g:'MVN antrun:run' – 2014-12-10 07:50:54

0

您可以通过Maven-Ant Plugin执行ant脚本,但为什么你需要Ant来检出你的项目?你没有把你的子项目组织在同一棵树上吗?

+1

我把任务标签之间的蚂蚁目标,我得到这个错误问题:未能创建任务或类型的目标 原因:该名称是undefined. – 2010-05-12 09:06:25

+0

@khmarbaise你没有组织你的子项目是在同一棵树“ - 你是什么意思? – 2010-05-12 09:12:00