jackyrong

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

<?xml version="1.0" encoding="UTF-8" ?>

<project name="AntTest" default="deploy" basedir=".">

 <property name="tomcat_home" value="d:/tomcat6" />
 <property name="jdk_home" value="d:/jdk6" />
 <property name="webapp.name" value="anttest" />
 <property name="build_dir" value="build/classes" />
 <property name="webapp.class.dir" value="${basedir}/WebContent/WEB-INF/classes" />
 <property name="tomcat_lib" value="${tomcat_home}/lib" />
 <property name="webapp_home" value="${tomcat_home}/webapps" />
 <property name="jdk_lib" value="${jdk_home}/lib" />
 <property name="jdk_bin" value="${jdk_home}/bin" />
 <property name="jdk_jre_lib" value="${jdk_home}/jre/lib" />

 <target name="clean">
  <echo>
   Cleaning the pre-built files or directories.
  </echo>

  <delete dir="${build_dir}" />
  <delete dir="${webapp_home}/${webapp.name}.war" />
  <delete dir="${webapp.class.dir}" />
  <delete file="${basedir}/${webapp.name}.war" />
  <delete file="${basedir}/${webapp.name}.jar"/>
  <delete dir="${webapp_home}/${webapp.name}" />
 </target>

 <target name="init_directory">
  <mkdir dir="${build_dir}" />
  <mkdir dir="${webapp.class.dir}" />
 </target>

 <target name="init_classpath">
  <path id="build.path">
   <pathelement location="${jdk_lib}" />
   <pathelement location="${jdk_jre_lib}" />
   <pathelement location="${ant.library.dir}/junit-4.1.jar"/>
   <fileset dir="${tomcat_lib}">
    <include name="**/*.jar" />
   </fileset>
  </path>
 </target>

 <target name="compile" depends="clean, init_directory, init_classpath">
  <echo message="Compile servlet!" />
  <javac destdir="${build_dir}" fork="yes" executable="${jdk_bin}/javac" debug="on">
   <src path="${basedir}/src" />
   <classpath refid="build.path" />
  </javac>
 </target>

 <target name="build_jar" depends="compile">
  <jar destfile="${basedir}/${webapp.name}.jar">
   <fileset dir="${build_dir}" includes="**/*.class" />
  </jar>
 </target>

 <target name="war" depends="compile">
  <copy todir="${webapp.class.dir}">
   <fileset dir="${build_dir}" includes="**/*.class" />
  </copy>
  <war destfile="${basedir}/${webapp.name}.war" update="true" webxml="${basedir}/WebContent/WEB-INF/web.xml">
   <classes dir="${webapp.class.dir}" />
   <zipfileset dir="${basedir}/WebContent">
    <exclude name="**/*.Thumb" />
   </zipfileset>
  </war>
 </target>

 <target name="runtests" depends="compile" description="Run JUnit Test for Project">
  <java fork="yes" classname="junit.textui.TestRunner" taskname="junit" failonerror="true">
   <arg value="test.servlet.UserUtilTest" />
   <classpath>
    <pathelement location="${build_dir}" />
    <pathelement path="${java.class.path}" />
   </classpath>
  </java>
 </target>
 
 <target name="runtests1" depends="init_classpath" description="Run Junit tests">
  <junit printsummary="yes">
   <classpath>
     <pathelement location="${build_dir}"/>
   </classpath>

   <formatter type="plain"/>

   <batchtest fork="no" todir="c:/">
     <fileset dir="${basedir}/src">
       <include name="**/*Test.java"/>
     </fileset>
   </batchtest>
  </junit>
 </target>

 <target name="deploy" depends="war">
  <copy file="${basedir}/${webapp.name}.war" tofile="${webapp_home}/${webapp.name}.war" />
 </target>

 <target name="start_tomcat">
  <exec executable="${tomcat_home}/bin/startup.bat" />
 </target>

 <target name="stop_tomcat">
  <exec executable="${tomcat_home}/bin/shutdown.bat" />
 </target>

</project>

posted on 2008-12-30 11:14  jackyrong的世界  阅读(567)  评论(0编辑  收藏  举报