build.properties
# -----------------------------------------------------------------------------
# build.properties
# This file is referenced by the sample build.xml file.
# -----------------------------------------------------------------------------
build.version=1.0.0
#you need these jars
svnant.jar=/usr/local/ant/lib/svnant.jar
svnClientAdapter.jar=/usr/local/ant/lib/svnClientAdapter.jar
svnjavahl.jar=/usr/local/ant/lib/svnjavahl.jar
javaEE.lib=/opt/tomcat-7/lib
#tomcat information
#tomcat home
tomcat.home=/opt/tomcat-7
#tomcat project deploy dir
tomcat.deploy=${tomcat.home}/webapps/${ant.project.name}
debuglevel=source,lines
target=1.6
source=1.6
work.space=/tmp/project
build.dir=${work.space}/WebRoot/WEB-INF/classes
lib.dir=${work.space}/WebRoot/WEB-INF/lib
java.source=${work.space}/src
java.config=${work.space}/config
web.dir=${work.space}/WebRoot
resource.dir=${work.space}/resources
zip.file=${tomcat.deploy}/${ant.project.name}.zip
#project information in SVN
urlRepos=svn://192.168.1.114/project/lottery
svn.user=xxx
svn.passwd=xxxx
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="lottery" default="auto">
<!-- all properties are in build.properties -->
<property file="build.properties" />
<!-- svn runtime libs -->
<path id="svnant.lib">
<pathelement location="${svnjavahl.jar}" />
<pathelement location="${svnant.jar}" />
<pathelement location="${svnClientAdapter.jar}" />
</path>
<!--java EE 库 -->
<path id="javaEE">
<fileset dir="${javaEE.lib}">
<include name="**/*.jar" />
</fileset>
</path>
<!-- load the libs in classpath -->
<path id="project.classpath">
<pathelement location="${build.dir}"/>
<fileset dir="${lib.dir}"/>
</path>
<!-- clean up -->
<target name="clear">
<delete dir="${work.space}"></delete>
<delete dir="${tomcat.home}/work/Catalina/localhost/${ant.project.name}"></delete>
<delete dir="${tomcat.deploy}/${ant.project.name}"></delete>
<delete dir="${tomcat.deploy}/${ant.project.name}.war"></delete>
</target>
<!-- load the svn task -->
<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classdata-path="svnant.jar" />
<svnSetting id="svn.settings" javahl="false" svnkit="true" username="${svn.user}" password="${svn.passwd}" />
<!--svn checkout-->
<target name="svn" depends="clear">
<mkdir dir="${work.space}"/>
<svn refid="svn.settings">
<checkout url="${urlRepos}" destdata-path="${work.space}" />
</svn>
</target>
<!--compile the project-->
<target name="compile" depends="svn" description="----------compile ${ant.project.name}-----------">
<echo message="----------compile ${ant.project.name}:${ant.file}-----------"></echo>
<mkdir dir="${build.dir}"/>
<copy includeemptydirs="false" todir="${build.dir}">
<fileset dir="${java.source}" excludes="**/*.launch, **/*.java"></fileset>
<fileset dir="${java.config}" excludes="**/*.launch, **/*.java"></fileset>
</copy>
<javac includeantruntime="false" includejavaruntime="true" debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" source="${source}" target="${target}" encoding="utf-8">
<src data-path="${java.source}" />
<exclude name="config/"/>
<classpath>
<path refid="project.classpath">
</path>
<path refid="javaEE">
</path>
</classpath>
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-Xlint:deprecation"/>
</javac>
</target>
<!--compress and pack -->
<!--deploy to the tomcat project dir-->
<target name="deploy" depends="compile">
<mkdir dir="${tomcat.home}/webapps/${ant.project.name}"/>
<zip destfile="${zip.file}">
<zipfileset dir="${web.dir}"/>
</zip>
<unzip dest="${tomcat.home}/webapps/${ant.project.name}" overwrite="true" src="${zip.file}"/>
</target>
<!--shutdowntomcat-->
<target name="shutdowntomcat" description="========shutdowntomcat===========">
<exec executable="${tomcat.home}/bin/shutdown.sh" failοnerrοr="false">
</exec>
<sleep seconds="10" />
</target>
<!--startuptomcat-->
<target name="startuptomcat" description="========startuptomcat===========">
<sleep seconds="5" />
<exec executable="${tomcat.home}/bin/startup.sh" failοnerrοr="true" >
</exec>
</target>
<!--Done,restart tomcat-->
<target name="auto" depends="shutdowntomcat,deploy,startuptomcat">
<echo message="All DONE!!!!" />
</target>
</project>
在安装了ant的环境下面运行 build.xml
上面的tomcat的目录需要自己制定,svn的信息也需要自己设定,配置信息都在build.properties文件中