用Ant实现SVN代码更新,部署

要实现ant可以从svn服务器上检出代码要使用svnant jar文件。
从网上下载svnant 包,下载地址:
http://subclipse.tigris.org/files/documents/906/49042/svnant-1.3.1.zip
将下载好的svnant 解压将 lib目录下的所有jar复制到ant主目录中的 lib目录下。

编写build.xml
要svn task任务可以使用要在build.xml中添加

  1. <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" />   

完整的xml文件如下:

  1. <project name="dt" basedir=".">  
  2.     <!--定义属性-->  
  3.     <property name="src" value="src/main/java" />  
  4.     <property name="resources" value="src/main/resources"/>  
  5.     <property name="test" value="test"></property>  
  6.     <property name="target" value="target"></property>  
  7.     <property name="main-target" value="target/classes"/>  
  8.     <property name="test-target" value="target/test-classes"/>  
  9.     <property name="lib-dir" value="WebContent/WEB-INF/lib"/>  
  10.     <property name="tomcat.home" value="D:/webapp-server/apache-tomcat-6.0.20"/>  
  11.     <!--ant lib目录>  
  12.     <property name="ant-lib-dir" value="D:/apache-ant-1.8.2/lib"/>  
  13.     <!-- 需指向本地tomcat lib目录 -->  
  14.     <property name="tomcat-lib" value="D:/webapp-server/apache-tomcat-6.0.20/lib"/>  
  15.     <!-- svn路径 -->  
  16.     <property name="urlRepos" value="svn://192.168.1.1o/Project/dt" />  
  17.     <!-- 定义classpath-->  
  18.     <path id="classpath">  
  19.         <fileset dir="${lib-dir}" includes="***.jar"></fileset>  
  20.         <fileset dir="${tomcat-lib}" includes="***.jar"></fileset>  
  21.     </path>  
  22.     <!-- 引用svn task文件,使用svn任务可以使用-->  
  23.     <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" />  
  24.     <!-- 清理-->  
  25.     <target name="clean">  
  26.         <delete dir="${target}"></delete>  
  27.     </target>  
  28.     <!-- 初始化-->  
  29.     <target name="init" depends="clean">  
  30.            
  31.         <mkdir dir="${main-target}"/>  
  32.         <mkdir dir="${test-target}"/>  
  33.     </target>  
  34.     <!-- 设置svn相关属性 -->  
  35.     <svnSetting id="svn.setting" svnkit="true" username="hzl" password="111111"  javahl="false" />  
  36.     <!-- 检出代码 这里使用 export 不是checkout 二者区别 checkout会svn相关信息文件检出,export只是检出最新的文件-->  
  37.     <target name="checkout" depends="clean">  
  38.         <svn refid="svn.setting">  
  39.             <export srcUrl="${urlRepos}" destPath="." force="true"/>  
  40.         </svn>  
  41.     </target>  
  42.     <!-- 编译 -->  
  43.     <target name="compile" depends="checkout">  
  44.         <javac srcdir="${src}" destdir="${main-target}" encoding="UTF-8" includeAntRuntime="false">  
  45.             <classpath refid="classpath"></classpath>  
  46.         </javac>  
  47.         <copy todir="${main-target}">  
  48.             <fileset dir="${resources}">  
  49.                 <exclude name="sql/**"/>  
  50.             </fileset>  
  51.         </copy>  
  52.     </target>  
  53.     <!-- 打war包 -->  
  54.     <target name="build" depends="compile">  
  55.            
  56.         <war destfile="${target}/dt.war" webxml="WebContent/WEB-INF/web.xml">  
  57.             <fileset dir="WebContent"></fileset>  
  58.             <classes dir="${main-target}"></classes>  
  59.         </war>  
  60.         <delete dir="${main-target}"></delete>  
  61.         <delete dir="${test-target}"></delete>  
  62.     </target>  
  63.        
  64.     <!--shutdowntomcat-->  
  65.     <target name="shutdowntomcat" description="========shutdowntomcat===========">  
  66.         <exec executable="${tomcat.home}/bin/shutdown.sh" failonerror="false"></exec>  
  67.         <sleep seconds="10"/>  
  68.     </target>  
  69.        
  70.     <!--startuptomcat-->  
  71.     <target name="startuptomcat" description="========startuptomcat===========">  
  72.         <sleep seconds="5"/>  
  73.         <exec executable="${tomcat.home}/bin/startup.sh" failonerror="false"></exec>  
  74.     </target>  
  75.   
  76.     <!--部署到tomcat下面-->  
  77.     <target name="deploy" depends="war">  
  78.         <copy file="${target}/dt.war" todir="${tomcat.home}/webapps" />  
  79.     </target>    
  80. </project>    
  1. da shang
    donate-alipay
               donate-weixin weixinpay

发表评论↓↓