這段ant腳本主要作用就是:自動從SVN庫拉最新的代碼,編譯、并自動部署到測試服務器。
其中用到了“antsvn” ,有3個jar包需要配置進去
<?xml version="1.0" encoding="UTF-8"?>
<!-- wei.songw 2008.3.19 -->
<project basedir="." name="smmail" default="auto">
<!-- all properties are in build.properties -->
<property file="build.properties" />
<!--svn本身需要的運行庫 -->
<path id="svnant.lib">
<pathelement location="${svnjavahl.jar}" />
<pathelement location="${svnant.jar}" />
<pathelement location="${svnClientAdapter.jar}" />
</path>
<!--java EE 1.4 庫 -->
<path id="javaEE1.4">
<fileset dir="${javaEE1.4.lib}">
<include name="**/*.jar" />
</fileset>
</path>
<!--項目的classpath庫 -->
<path id="project.classpath">
<pathelement location="${build.dir}" />
<fileset dir="${lib.dir}" />
</path>
<!--清理項目任務(干掉下載目錄,tomcat原來的部署文件) -->
<target name="clear">
<delete dir="${work.space}" />
<delete dir="${tomcat.home}/work/Catalina/localhost/${ant.project.name}" />
<delete dir="${tomcat.home}/webapps/${ant.project.name}" />
<delete dir="${tomcat.home}/webapps/${ant.project.name}.war" />
</target>
<!-- load the svn task -->
<taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="svnant.lib" />
<!--svn同步任務-->
<target name="svn" depends="clear">
<mkdir dir="${work.space}"/>
<svn username="SongWei" password="Song" javahl="false">
<checkout url="${urlRepos}" destPath="${work.space}" />
</svn>
</target>
<!--編譯-->
<target name="compile" depends="svn" description="======compile project======">
<echo message="compile==========>${ant.project.name}: ${ant.file}" />
<mkdir dir="${build.dir}" />
<copy includeemptydirs="false" todir="${build.dir}">
<fileset dir="${java.source}" excludes="**/*.launch, **/*.java, config/*.*"/>
</copy>
<copy includeemptydirs="false" todir="${build.dir}">
<fileset dir="${java.config}" excludes="**/*.launch, **/*.java"/>
</copy>
<javac includejavaruntime="true" debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" source="${source}" target="${target}" encoding="utf-8">
<src path="${java.source}" />
<exclude name="config/"/>
<classpath>
<path refid="project.classpath">
</path>
<path refid="javaEE1.4">
</path>
</classpath>
</javac>
<javac debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" source="${source}" target="${target}" encoding="utf-8">
<src path="${java.config}" />
</javac>
</target>
<!--壓縮,打包-->
<target name="war" depends="compile" description="======compress j2ee war file======">
<mkdir dir="${dist.dir}" />
<!--compress j2ee war file-->
<war destfile="${war.file}" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}" />
<classes dir="${build.dir}" />
<lib dir="${lib.dir}" />
</war>
</target>
<!--shutdowntomcat-->
<target name="shutdowntomcat" description="========shutdowntomcat===========">
<exec executable="${tomcat.home}/bin/shutdown.sh" failonerror="false"></exec>
<sleep seconds="10"/>
</target>
<!--startuptomcat-->
<target name="startuptomcat" description="========startuptomcat===========">
<sleep seconds="5"/>
<exec executable="${tomcat.home}/bin/startup.sh" failonerror="false"></exec>
</target>
<!--部署到tomcat下面克-->
<target name="deploy" depends="war">
<copy file="${war.file}" todir="${tomcat.home}/webapps" />
</target>
<!--全自動無敵部署,啟動關閉tomcat-->
<target name="auto" depends="shutdowntomcat,deploy,startuptomcat">
<echo message="DONE!!!!" />
</target>
</project>
下面是build.xml指定的properties文件,需要和build.xml放在同一個目錄下面
需要指定work.space(svn拉下來代碼的存放,已經編譯,打包用的臨時目錄)
tomcat.home(tomcat服務器的根目錄,如果是其他服務器,需要修改對應項)
===============================================
build.version=1.0.0
svnant.jar=/usr/java/svn/svnant.jar
svnClientAdapter.jar=/usr/java/svn/svnClientAdapter.jar
svnjavahl.jar=/usr/java/svn/svnjavahl.jar
javaEE1.4.lib=/usr/javaEE-1.4
debuglevel=source,lines
target=1.6
source=1.6
work.space=/home/gmail/workspace
dist.dir=${work.space}
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}/src/config
web.dir=${work.space}/WebRoot
resource.dir=${work.space}/resources
tomcat.home=/home/gmail/tomcat6
war.file=${dist.dir}/${ant.project.name}.war
urlRepos=svn://192.168.1.100/product/SMMAIL/Develop
posted on 2010-04-09 11:23
暗夜教父 閱讀(1827)
評論(0) 編輯 收藏 引用 所屬分類:
JAVA