luyibo 2011-09-27
最近项目上要部署工程了,做了一个利用svn+ant 方式 自动构建工程并部署。觉得以后部署可以省好多事情。觉得很不错。这次只需要部署java 后台进程,写个随笔吧。以后可以扩展到 WEB 应用 war 等方式,呵呵,ANT 无所不能!
闲话不多说,上代码:
<project name="workflow" default="all" basedir="."> <description> simple example build file </description> <!-- set global properties for this build --> <property name="frame.checkout.dir" location="/usr/workflow/srcs/frame" /> <property name="frame.src" location="/usr/workflow/srcs/frame/src" /> <property name="frame.bin" location="/usr/workflow/bin/frame/classes" /> <property name="dataaccess.checkout.dir" location="/usr/workflow/srcs/dataaccess" /> <property name="dataaccess.src" location="/usr/workflow/srcs/dataaccess/src" /> <property name="dataaccess.bin" location="/usr/workflow/bin/dataaccess/classes" /> <property name="engine.checkout.dir" location="/usr/workflow/srcs/engine" /> <property name="engine.src" location="/usr/workflow/srcs/engine/src" /> <property name="engine.bin" location="/usr/workflow/bin/engine/classes" /> <property name="libs.checkout.dir" location="/usr/workflow/libs" /> <property name="workflow.jar" location="/usr/workflow/jar" /> <property name="ant.lib" location="/usr/local/apache-ant-1.8.1/lib" /> <property name="svn.path" value="svn://192.168.32.115/workflow" /> <path id="svnant.classpath"> <fileset dir="${ant.lib}"> <include name="**/*.jar" /> </fileset> </path> <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.classpath" /> <target name="frame.checkout"> <svn username="zengke" password="zengke"> <checkout url="${svn.path}/srcs/frame" revision="HEAD" destPath="${frame.checkout.dir}" /> </svn> </target> <target name="dataaccess.checkout"> <svn username="zengke" password="zengke"> <checkout url="${svn.path}/srcs/dataaccess" revision="HEAD" destPath="${dataaccess.checkout.dir}" /> </svn> </target> <target name="engine.checkout"> <svn username="zengke" password="zengke"> <checkout url="${svn.path}/srcs/engine" revision="HEAD" destPath="${engine.checkout.dir}" /> </svn> </target> <target name="libs.checkout"> <svn username="zengke" password="zengke"> <checkout url="${svn.path}/libs" revision="HEAD" destPath="${libs.checkout.dir}" /> </svn> </target> <path id="compile.classpath"> <pathelement path="${frame.bin}" /> <pathelement path="${dataaccess.bin}" /> <pathelement path="${engine.bin}" /> <fileset dir="${libs.checkout.dir}"> <include name="das/**/*.jar" /> <include name="sdo/**/*.jar" /> <include name="engine/**/*.jar" /> <include name="carefx/**/*.jar" /> <include name="third_part/**/*.jar" /> </fileset> </path> <target name="all" depends="init,frame.checkout,dataaccess.checkout,engine.checkout,copyfiles,compile,frame,dataaccess,engine,startEngine" /> <target name="init"> <!-- Create the time stamp --> <tstamp /> <!-- Create the build directory structure used by compile --> <mkdir dir="${frame.bin}" /> <mkdir dir="${dataaccess.bin}" /> <mkdir dir="${engine.bin}" /> <mkdir dir="${workflow.jar}" /> </target> <target name="copyfiles" depends="libs.checkout,frame.checkout,dataaccess.checkout,engine.checkout,init"> <copy todir="${frame.bin}"> <fileset dir="${frame.checkout.dir}/src/main/resources"> <include name="**/**" /> <exclude name="**/config_cf.xml" /> <exclude name="**/config_da.xml" /> </fileset> </copy> <copy todir="${dataaccess.bin}"> <fileset dir="${dataaccess.checkout.dir}/src/main/resources"> <include name="**/**" /> </fileset> </copy> <copy todir="${engine.bin}"> <fileset dir="${engine.checkout.dir}/src/main/resources"> <include name="**/**" /> </fileset> </copy> </target> <target name="compile" depends="copyfiles" description="compile the source "> <!-- Compile the java code from ${src} into ${build} --> <javac destdir="${frame.bin}" includeAntRuntime="false" srcdir="${frame.checkout.dir}"> <compilerarg line="-encoding UTF-8" /> <classpath refid="compile.classpath" /> </javac> <javac destdir="${dataaccess.bin}" includeAntRuntime="false" srcdir="${dataaccess.checkout.dir}"> <compilerarg line="-encoding UTF-8" /> <classpath refid="compile.classpath" /> </javac> <javac destdir="${engine.bin}" includeAntRuntime="false" srcdir="${engine.checkout.dir}"> <compilerarg line="-encoding UTF-8" /> <classpath refid="compile.classpath" /> </javac> </target> <target name="frame" depends="compile"> <jar destfile="${workflow.jar}/frame.jar" basedir="${frame.bin}"> <include name="**/**" /> </jar> </target> <target name="dataaccess" depends="compile"> <jar destfile="${workflow.jar}/dataaccess.jar" basedir="${dataaccess.bin}"> <include name="**/**" /> </jar> </target> <target name="engine" depends="compile"> <jar destfile="${workflow.jar}/engine.jar" basedir="${engine.bin}"> <include name="**/**" /> </jar> </target> <target name="startEngine" depends="frame,dataaccess,engine" description="run"> <echo message="----------- Engine start begin ------------" /> <java classname="com.carefx.workflow.test.ServerStart" fork="yes"> <classpath refid="compile.classpath" /> </java> <echo message="----------- Engine start end ------------" /> </target> <target name="startDataAccess" depends="frame,dataaccess" description="run"> <echo message="----------- DataAccess start begin ------------" /> <java classname="com.carefx.dataaccess.server.impl.mina.MinaDataAccessServer" fork="yes"> <classpath refid="compile.classpath" /> </java> <echo message="----------- DataAccess start end ------------" /> </target> </project>