另一个好的ant文件收藏

来源:互联网 发布:游戏网站源码代理 编辑:程序博客网 时间:2024/04/29 18:32

 <?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>

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jackyrongvip/archive/2008/12/30/4607454.aspx

原创粉丝点击