发表时间:2009-06-17
最后修改:2010-12-29
最近写了一个部署打包的ant,功能真强大,自动更新svn源码,部署到Tomcat下后,重启tomcat服务器~~
其中svn运行的命令必须安装subversion~~
deploy.bat
call ant -f ./deploy.xml -debug -l deploy.log
deploy.xml
<project name="deploy" default="autodeploy" basedir=".">
<property name="zjdd.dir" value="./ZJDD"/>
<property name="pkgs.dir" value="./pkgs"/>
<property environment="env" />
<property name="tomcat.home" value="${env.TOMCAT_HOME}"/>
<tstamp>
<format property="deploy.time" pattern="yy-MM-dd HH.mm" />
</tstamp>
<target name="uptsvn">
<echo>+ ===================================================== +</echo>
<echo>+ +</echo>
<echo>+ updating code from svn +</echo>
<echo>+ +</echo>
<echo>+ ===================================================== +</echo>
<exec executable="svn">
<arg line="update ${zjdd.dir} "/>
</exec>
<exec executable="cmd">
<arg line="/c"/>
<arg line="svnversion ${zjdd.dir} >>svn.txt"/>
</exec>
<move file="./svn.txt" todir="${zjdd.dir}/ZJDD_ZJ000_CommonLib/apps/WebContent" failonerror="false"/>
</target>
<target name="ant_app" depends="uptsvn">
<echo>+ ===================================================== +</echo>
<echo>+ +</echo>
<echo>+ anting application to war and ear +</echo>
<echo>+ +</echo>
<echo>+ ===================================================== +</echo>
<ant dir="${zjdd.dir}/ZJDD_ZJ000_CommonLib/apps" antfile="build.xml" inheritall="off"/>
</target>
<target name="mv_to_pack" depends="ant_app">
<delete dir="${pkgs.dir}\${deploy.time}" />
<mkdir dir="${pkgs.dir}\${deploy.time}" />
<move file="${zjdd.dir}/cbms.ear" todir="${pkgs.dir}/${deploy.time}" />
<copy file="${zjdd.dir}/cbms.war" todir="${tomcat.home}/webapps" />
<move file="${zjdd.dir}/cbms.war" todir="${pkgs.dir}/${deploy.time}" />
</target>
<target name="execute" depends="mv_to_pack">
</target>
<!--shutdown-->
<target name="shutdown" description="========shutdowntomcat===========">
<exec executable="${tomcat.home}/bin/shutdown.bat" failonerror="false"></exec>
<sleep seconds="1"/>
</target>
<!--startup-->
<target name="startup" depends="shutdown" description="========startuptomcat===========">
<sleep seconds="3"/>
<exec executable="${tomcat.home}/bin/startup.bat" failonerror="false"></exec>
</target>
<!--autodeploy-->
<target name="autodeploy" depends="execute,startup">
</target>
</project>
build.xml
<project name="ear" default="deploy" basedir=".">
<property environment="env" />
<property file="${basedir}/build.properties" />
<property name="zjdd.dir" value="${basedir}/../.." />
<property name="builder.dir" value="${zjdd.dir}/builder" />
<property name="src.dir" value="${builder.dir}/src" />
<property name="webcontent.dir" value="${builder.dir}/WebContent" />
<property name="classes.dir" value="${webcontent.dir}/WEB-INF/classes" />
<property name="lib.dir" value="${webcontent.dir}/WEB-INF/lib" />
<path id="build.classpath" description="complie 's classpath">
<fileset dir="${webcontent.dir}/WEB-INF/lib">
<include name="*.jar" />
</fileset>
<pathelement location="${classes.dir}" />
</path>
<target name="copy-files" description="copy,java files">
<delete dir="${builder.dir}" />
<mkdir dir="${builder.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${lib.dir}" />
<mkdir dir="${webcontent.dir}/apps" />
<mkdir dir="${src.dir}" />
<copy todir="${src.dir}" overwrite="YES">
<fileset dir="${zjdd.dir}/TEST/ProductCode" />
</copy>
<copy todir="${webcontent.dir}" overwrite="yes">
<fileset dir="${basedir}/WebContent" excludes=".svn" />
</copy>
<copy todir="${webcontent.dir}/apps" overwrite="yes">
<fileset dir="${zjdd.dir}/TEST/WebContent/app">
<exclude name="**/*.zh" />
<exclude name="**/*_zh.js" />
</fileset>
</copy>
</target>
<!-- compile file to sharelib -->
<target name="compile" depends="copy-files">
<mkdir dir="${classes.dir}" />
<javac fork="true" memoryInitialSize="256m" memoryMaximumSize="500m" srcdir="${src.dir}" destdir="${classes.dir}" includes="**" encoding="UTF-8" debug="true">
<classpath refid="build.classpath" />
</javac>
<copy todir="${classes.dir}">
<fileset dir="${src.dir}" excludes="**/*.java" />
</copy>
</target>
<!-- create the war -->
<target name="web-war" depends="compile" description="create war">
<war destfile="${builder.dir}/../cbms.war" webxml="${webcontent.dir}/WEB-INF/web.xml">
<fileset dir="${webcontent.dir}">
</fileset>
</war>
</target>
<!-- create the ear -->
<target name="ear" depends="web-war" description="create ear">
<ear destfile="${builder.dir}/../cbms.ear" appxml="${basedir}/META-INF/META-INF/application.xml" duplicate="preserve">
<fileset dir="${basedir}/META-INF" includes="**/*.*" />
<fileset dir="${builder.dir}/..">
<include name="cbms.war" />
</fileset>
</ear>
</target>
<target name="deploy" depends="ear">
<echo>+ ===================================================== +</echo>
<echo>+ +</echo>
<echo>+ Building Complete, Cleaning Temporary Files...... +</echo>
<echo>+ +</echo>
<echo>+ ===================================================== +</echo>
<delete dir="${builder.dir}">
</delete>
</target>
</project>
--TortoiseSVN-1.6.10