项目中用到的ant脚本,大多数可以重用。贴在这里做参考。
<project name="MQ_Transfer" default="jar" basedir=".">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="res.dir" value="res"/>
<property name="doc.dir" value="doc"/>
<property name="lib.dir" value="lib"/>
<property name="web.dir" value="defaultroot"/>
<property name="deploy.path" value="c:/tomcat/webapp"/>
<property name="jarname" value="sysway_oa_mq.jar"/>
<property name="warname" value="sysway_oa_mq.war"/>
<property name="tomcat.home" value="D://swoa_xwf//tomcat4.1.12"/>
<property name="tomcat.manager.url" value="http://localhost:8080/manager"/>
<property name="tomcat.username" value="tomcat"/>
<property name="tomcat.password" value="tomcat"/>
<path id="compile_lib">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<!-- del dir -->
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<!-- make dir -->
<target name="init" depends="clean">
<mkdir dir="${build.dir}"/>
</target>
<!--compile -->
<target name="compile" depends="clean,init">
<javac srcdir="${src.dir}" destdir="${build.dir}" debug="on">
<classpath refid="compile_lib"/>
</javac>
</target>
<!-- make jar -->
<target name="jar" depends="compile">
<jar destfile="${jarname}">
<fileset dir="${build.dir}"
excludes="**/Test*.class"
/>
<fileset dir="${res.dir}"
includes="**/*"
/>
</jar>
</target>
<!-- run the test class -->
<target name="runtest" depends="compile">
<java classname="com.sysway.oa.service.transfer.TestSendAndGet">
<classpath>
<pathelement location="${build.dir}"/>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${res.dir}">
<include name="**/*"/>
</fileset>
</classpath>
</java>
</target>
<!-- make war -->
<target name="war" depends="compile">
<war destfile="${warname}"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
</war>
</target>
<!-- deploy war to tomcat -->
<target name="deploywar" depends="war">
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<!-- delete jar file in oa system -->
<target name="delete">
<delete file="D://swoa_xwf//site//WEB-INF//lib//${jarname}"/>
</target>
<!-- copy to oa system -->
<target name="copy" depends="delete,jar">
<copy todir="D://swoa_xwf//site//WEB-INF//lib" preservelastmodified="true">
<fileset dir=".">
<include name="*.jar"/>
</fileset>
</copy>
</target>
<!-- ============================================================== -->
<!-- Tomcat tasks -->
<!-- ============================================================== -->
<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
<classpath>
<path location="${tomcat.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
<classpath>
<path location="${tomcat.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
<classpath>
<path location="${tomcat.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath>
<path location="${tomcat.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath>
<path location="${tomcat.home}/server/lib/catalina-ant.jar"/>
</classpath>
</taskdef>
<target name="startTomcat" description="Start Tomcat application">
<start url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path="D:/swoa_xwf/site"/>
</target>
<target name="stopTomcat" description="Stop Tomcat application">
<stop url="${tomcat.manager.url}"
username="${tomcat.username}"
password="${tomcat.password}"
path=""/>
</target>
</project>