Ant编译部署

Author: 江南白衣

      HomePage:  http://ant.apache.org

      一份比较好的文档:http://dev.csdn.net/article/72718.shtm

      SpringSide的disc/extra-lib/ant目录已包含了运行ant所需的几个最重要的jar文件,用build.bat即可运行ant,无需独立安装Ant。

      1.Ant脚本目前提供的功能如下:

        <echo message="compile     --> 编译Java文件并复制资源文件"/>
        <echo message="war         --> 生成war文件"/>
        <echo message="test        --> 运行JUnit测试"/>
        <echo message="test-report --> 生成JUnit测试结果报表"/>
        <echo message="jar         --> 生成Springside Framework类库的jar"/>
        <echo message="new         --> 在SpringSide的基础上创建应用项目"/>
        <echo message="idea        --> 生成IDEA5.1默认项目文件"/>
        <echo message="eclipse     --> 生成Eclipse3.1默认项目文件"/>
        <echo message="wtp         --> 生成Eclipse wtp默认项目文件"/>
        <echo message="myeclipse   --> 生成MyEclipse默认项目文件"/>
        <echo message="release     --> 生成SpringSide发布文件"/>
        <echo message= "maven-all-jars-->使用Maven2管理jar"/>

  2.看点:

      1.compile中的Java文件编译,ClassPath设置与复制其他后缀名的资源文件。

      2.war中的 war打包,manifest文件生成 与 timestamp,buildnumber应用。

      3.test中的unit test。

      4.usage中的input让用户输入要执行的task, antcall执行。

      5.microdef简化IDE copy。

3.Ant-Contrib

Ant-Contrib(网站)的<If>和<For>Task 绝对是使用Ant编写脚本的最重要补充,SprngSide Plugin部分的脚本全靠它才编写出来的。

    <if>
     <os family="unix"/>
    <then>
     <property name="ext" value="sh"/>
     </then>
     <else>
       <property name="ext" value="bat"/>
     </else>
  </if>

以下一段循环 plugins目录,执行Install脚本

<for param="plugindir">
   <path>
        <dirset dir="plugins">
          <depth max="0"/>
       </dirset>
   </path>
   <sequential>
        <exec executable="@{plugindir}/install.${ext}" dir="@{plugindir}"/>
    </sequential>
</for>