ant build.xml编撰

ant build.xml编写
<?xml version="1.0"  encoding="UTF-8" ?>
<project name="projectname" default="compile" basedir="." >

<!--临时变量-->
<property name="server.lib" location="C:/tool/tomcat/apache-tomcat-6.0.35/lib"></property>
<property name="java-lib" location="C:\Program Files (x86)\Java\jdk1.6.0_10\jre\lib"></property>
<property name="jar-name" value="ring.jar"></property>
<property name="war-name" value="ring.war"></property>
<!--项目目录-->
   <property name="src" location="src"/>
   <property name="WebRoot" location="WebRoot"></property>
   <property name="META-INF" location="${WebRoot}/META-INF"></property>
   <property name="WEB-INF" location="${WebRoot}/WEB-INF"></property>
   <property name="web.classes" location="${WEB-INF}/classes"></property>
   <property name="web.lib" location="${WEB-INF}/lib"></property>
  
<!-- 项目构建目录-->
   <property name="build" location="build"/>
    <property name="build.src" location="${build}/src"/>
    <property name="build.lib" location="${build}/lib"/>
<property name="build.classes" location="${build}/classes"/>
     <property name="build.dist" location="${build}/dist"/>
<!--测量目录-->
<property name="src-test" location="test"/>
<property name="test" location="${build}/test"></property>
<property name="test.classes" location="${test}/classes"></property>
<property name="test.report" location="${test}/report"></property><!--测试报告-->
<!--测试报告-->
<property name="doc" location="${build}/doc"></property>
   
<!--系统环境属性-->
    <property environment="env" />
   
<!-- 外部文件-->
<!--
<property file="build.properties"/>
-->
<!-- 创建项目目录 -->
   <target name="createDir">
      <!-- 以下项目目录 -->
      <mkdir dir="${src}"/>
      <mkdir dir="${WebRoot}"/>
      <mkdir dir="${META-INF}"/>
      <mkdir dir="${WEB-INF}"/>
      <mkdir dir="${web.classes}"/>
      <!-- 以下项目构建目录 -->
       <mkdir dir="${build}"/>
       <mkdir dir="${build.src}"/>
       <mkdir dir="${build.classes}"/>
       <mkdir dir="${build.lib}"/>
       <mkdir dir="${build.dist}"/>
     <!--以下创建测试目录-->
     <mkdir dir="${src-test}"/>
     <mkdir dir="${test}"/>
     <mkdir dir="${test.classes}"/>
     <mkdir dir="${test.report}"/>
     <!--以下创建文档目录-->
   <mkdir dir="${doc}"/>
   </target>
  <!--编译路径设置-->
<path id="compile-path">

<fileset dir="${web.lib}" includes="**/*.jar"></fileset>
<fileset dir="${server.lib}" includes="**/*.jar"></fileset>

<fileset dir="${java-lib}" includes="**/*.jar"></fileset>
</path>
<path id="compile-test-path">
<path refid="compile-path"/>
<pathelement location="${build.classes}"/>
</path>
<path id="run-test-path">
<path refid="compile-test-path"></path>
<pathelement location="${build.dist}" />
</path>
<target name="clean">
<delete dir="${build}"></delete>
</target>
<!--编译-->
<target name="compile" depends="createDir">
<javac destdir="${build.classes}" srcdir="${src}"
includeantruntime="true"
classpathref="compile-path"
encoding="utf-8"
  />   
<copy todir="${build.classes}">
    <fileset dir="${src}" includes="**/*.properties,**/*.xml"/>
     </copy>
</target>
<!--编译测试-->
<target name="compile-test" depends="compile">
<javac destdir="${test.classes}"
   srcdir="${src-test}"
includeantruntime="true"
   classpathref="compile-test-path"
       encoding="utf-8"/>   
</target>
<!--执行测试-->
<target name="run-test" depends="compile-test">
<delete dir="${test}/html"></delete>

<junit fork="true" haltonfailure="false" failureproperty="junit.fail">
<classpath refid="run-test-path"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.report}">
<fileset dir="${test.classes}" includes="**/*.classes"/>
</batchtest>
</junit>
<junitreport todir="${test.report}">
<fileset dir="${test.report}" includes="TEST-*.xml"></fileset>
<report format="frames" todir="${test}/html"/>
</junitreport>
<echo>please see ${test}/html</echo>
<fail if="${junit.fail}" message="fail please review"/>
</target>
<!--打jar包-->
<target name="jar" depends="run-test">
<jar destfile="${build.dist}/${jar-name}" duplicate="preserve">
<fileset dir="${build.classes}" excludes="**/*.svn"></fileset>
</jar>
</target>
<target name="doc" depends="jar">
<delete dir="${doc}"></delete>
<mkdir dir="${doc}" />
<javadoc destdir="${doc}"
charset="UTF-8"
use="true"
encoding="UTF-8"
docencoding="UTF-8">
  <packageset dir="${src}">
    <include name="**"/>
  </packageset>
<classpath refid="compile-path"></classpath>
     </javadoc>
</target>
   
<!--打war包-->
<target name="war" depends="jar">
<war destfile="${build.dist}/${war-name}">
   <fileset dir="${WebRoot}" excludes="**/*.svn"></fileset>
</war>
</target>
</project>