Maven经验分享(四)执行ant脚本

ant是一个老牌的项目打包管理系统了,目前虽然已经慢慢被maven取代,但其功能的强大仍然是很多场合下的首选,尤其是众多的task可以基本满足任何需求。其实在maven中也有使用ant的需求,比如不同环境打包编译时使用不同的配置信息等,或者是说做一些文件删除、复制之类的事情,这有些是maven做不来的,而ant就可以了,况且maven中已经有了maven-antrun-plugin插件,专门为在maven中运行ant做好了准备。

<plugin> 
  <groupId>org.apache.maven.plugins</groupId>  
  <artifactId>maven-antrun-plugin</artifactId>  
  <version>1.7</version>  
  <executions> 
    <execution> 
      <phase>process-resources</phase>  
      <goals>
        <goal>run</goal>
      </goals>  
      <configuration> 
        <tasks> 
          <echo message="copy war ........"/>  
          <copy todir="${release.dir}"> 
            <fileset dir="../../target"> 
              <include name="*.war"/> 
            </fileset> 
          </copy>  
          <!-- 执行ant脚本-->
          <ant antfile="/maven/build_helpdoc.xml"/> 
        </tasks> 
      </configuration> 
    </execution> 
  </executions> 
</plugin>

 其中phase这个参数比较重要,如果是在copy打包用的jar、资源文件则必须其生命周期在package之前。

猜你喜欢

转载自lipengjavablog.iteye.com/blog/2170189
今日推荐