51Testing软件测试论坛
标题:
antsvn 自动更新和发布
[打印本页]
作者:
梦幻小丑灯
时间:
2018-6-15 16:33
标题:
antsvn 自动更新和发布
团队管理中,当项目非常多,而且发布频繁,手动发布往往非常繁琐,决定用自动化处理。
采用ant +svn+svnant
在网络上参考很多人的处理,组合成对自己比较实用的。
准备环境:
1、安装svn client 这个就不多说了。
2、安装ant,在这里我采用ant 1.8.3版本:
http://ant.apache.org/
,官网上下载zip 解压缩,并配置环境变量。
3、下载svnant ,并解压缩 ,把对应的lib\jar包放入 ant lib 包中。
下载地址:
http://subclipse.tigris.org/file ... 42/svnant-1.3.1.zip
这步很关键,不然svn命令运行不了!
思路:
1、固定一个目录,专门做发布目录,根据不同项目,在期底下建立与项目名称相同的目录。
2、建立build等目录,打成war包后删除对应的build包等操作
3、自动发布到tomcat
以下代码实现的是J2EE web工程打包发布
<p>
</p><p>[java] view plain copy</p><p><?xml version="1.0" encoding="UTF-8"?> </p><p> </p><p><project name="deploy" default="autodeploy" basedir="."> </p><p> <property environment="env" /> </p><p> <property name="projectName" value="svnant" /> </p><p> <property name="temporary.dir" value="D:/SVNTest/${projectName}"/> </p><p> </p><p> <property name="deployVersion.dir" value="${temporary.dir}/deployVersion"/> </p><p> <property name="tomcat.home" value="d:/apache-tomcat-6.0.32"/> </p><p> <property name="ant-lib.dir" value="F:/apache-ant-1.8.3/lib"/> </p><p> </p><p> <property name="svn.url" </p><p> value="http://subclipse.tigris.org/svn/subclipse/trunk/svnant/"/> </p><p> <property name="svn.name" value="guest"/> </p><p> <property name="svn.password" value=""/> </p><p> </p><p> <tstamp> </p><p> <format property="deploy.time" pattern="yy-MM-dd HH.mm" /> </p><p> </tstamp> </p><p> </p><p> <delete dir="${temporary.dir}" /> </p><p> <mkdir dir="${temporary.dir}" /> </p><p> </p><p> <path id="svnant.dir"> </p><p> <fileset dir="${ant-lib.dir}"> </p><p> <include name="ganymed.jar" /> </p><p> <include name="jna.jar" /> </p><p> </p><p> <include name="svnant.jar" /> </p><p> <include name="svnClientAdapter.jar" /> </p><p> <include name="svnjavahl.jar" /> </p><p> <include name="svnkit.jar" /> </p><p> </fileset> </p><p> </path> </p><p> <!-- define the svn task--> </p><p> <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" </p><p> classpathref="svnant.dir" /> </p><p> <!-- prepare for the checking out:clean the directory --> </p><p> <target name="prepare" </p><p> description="Prepare the dirs for the task"> </p><p> <delete dir="${temporary.dir}/${projectName}" /> </p><p> <mkdir dir="${temporary.dir}/${projectName}" /> </p><p> </target> </p><p> </p><p> </p><p> <target name="checkout" depends="prepare"> </p><p> <echo>+=========checkout start============+</echo> </p><p> <echo>+ +</echo> </p><p> <echo>+ +</echo> </p><p> <svn username="${svn.name}" password="${svn.password}" </p><p> javahl="false" failonerror="false" svnkit="true"> </p><p> <checkout url="${svn.url}" revision="HEAD" </p><p> destPath="${temporary.dir}/${projectName}" /> </p><p> </svn> </p><p> <echo>+ +</echo> </p><p> <echo>+========= checkout end ============+</echo> </p><p> </target> </p><p> </p><p> <target name="ant_app" depends="checkout"> </p><p> <echo>+ ======================== +</echo> </p><p> <echo>+ +</echo> </p><p> <echo>+ anting application to war and ear +</echo> </p><p> <echo>+ +</echo> </p><p> <echo>+ ======================== +</echo> </p><p> <ant dir="./" antfile="build.xml" inheritall="off"/> </p><p> </target> </p><p> </p><p> <target name="mv_to_pack" depends="ant_app"> </p><p> <delete dir="${deployVersion.dir}\${deploy.time}" /> </p><p> <mkdir dir="${deployVersion.dir}\${deploy.time}" /> </p><p> <move file="${temporary.dir}/${projectName}.war" todir="${deployVersion.dir}/${deploy.time}" /> </p><p> </target> </p><p> <target name="execute" depends="mv_to_pack"> </p><p> </target> </p><p> </p><p> <!--shutdown--> </p><p> <target name="shutdown" description="========shutdowntomcat==========="> </p><p> <exec executable="${tomcat.home}/bin/shutdown.bat" failonerror="false"> </p><p> </exec> </p><p> <sleep seconds="1"/> </p><p> <delete file="${tomcat.home}/webapps/${projectName}.war"> </p><p> </delete> </p><p> <delete dir="${tomcat.home}/webapps/${projectName}"> </p><p> </delete> </p><p> </target> </p><p> </p><p> <!--startup--> </p><p> <target name="startup" depends="shutdown" description="========startuptomcat==========="> </p><p> <copy file="${deployVersion.dir}/${deploy.time}/${projectName}.war" todir="${tomcat.home}/webapps" /> </p><p> <sleep seconds="3"/> </p><p> <exec executable="${tomcat.home}/bin/startup.bat" failonerror="false"> </p><p> </exec> </p><p> </target> </p><p> </p><p> <!--autodeploy--> </p><p> <target name="autodeploy" depends="execute,startup"> </p><p> <delete file="${temporary.dir}/${projectName}"> </p><p> </delete> </p><p> </target> </p><p></project> </p><p> </p><p>
</p>
复制代码
作者:
梦幻小丑灯
时间:
2018-6-15 16:33
<p>[java] view plain copy</p><p><?xml version="1.0" encoding="UTF-8"?> </p><p> <project name="ear" default="deploy" basedir="."> </p><p> <property environment="env" /> </p><p> <property name="projectName" value="svnant" /> </p><p> <property name="temporary.dir" value="D:/SVNTest/${projectName}"/> </p><p> </p><p> <property name="builder.dir" value="${temporary.dir}/builder" /> </p><p> <property name="project.dir" value="${temporary.dir}/${projectName}" /> </p><p> </p><p> <property name="src.dir" value="${builder.dir}/src" /> </p><p> <property name="WebRoot.dir" value="${builder.dir}/WebRoot" /> </p><p> <property name="classes.dir" value="${WebRoot.dir}/WEB-INF/classes" /> </p><p> <property name="lib.dir" value="${WebRoot.dir}/WEB-INF/lib" /> </p><p> </p><p> <path id="build.classpath" description="complie 's classpath"> </p><p> <fileset dir="${temporary.dir}/${projectName}/WebRoot/WEB-INF/lib"> </p><p> <include name="*.jar" /> </p><p> </fileset> </p><p> <!-- junit jar --> </p><p> <fileset dir="E:\eclipse\plugins"> </p><p> <include name="org.hamcrest.core_1.1.0.v20090501071000.jar" /> </p><p> </fileset> </p><p> </p><p> <fileset dir="E:\eclipse\plugins\org.junit_4.8.2.v4_8_2_v20110321-1705"> </p><p> <include name="junit.jar" /> </p><p> </fileset> </p><p> </p><p> <pathelement location="${classes.dir}" /> </p><p> </path> </p><p> </p><p> <target name="copy-files" description="copy,java files"> </p><p> <delete dir="${builder.dir}" /> </p><p> <mkdir dir="${builder.dir}" /> </p><p> <mkdir dir="${classes.dir}" /> </p><p> <mkdir dir="${lib.dir}" /> </p><p> <!-- </p><p> <mkdir dir="${WebRoot.dir}/apps" /> </p><p> --> </p><p> <mkdir dir="${src.dir}" /> </p><p> </p><p> <copy todir="${src.dir}" overwrite="YES"> </p><p> <fileset dir="${project.dir}/src" /> </p><p> </copy> </p><p> </p><p> <copy todir="${WebRoot.dir}" overwrite="yes"> </p><p> <fileset dir="${temporary.dir}/${projectName}/WebRoot" excludes=".svn" /> </p><p> </copy> </p><p> </p><p> </p><p> </target> </p><p> </p><p> <!-- compile file to share lib --> </p><p> <target name="compile" depends="copy-files"> </p><p> <mkdir dir="${classes.dir}" /> </p><p> </p><p> </p><p> <javac fork="true" memoryInitialSize="256m" memoryMaximumSize="500m" srcdir="${src.dir}" destdir="${classes.dir}" includes="**" encoding="UTF-8" debug="true"> </p><p> <classpath refid="build.classpath" /> </p><p> </javac> </p><p> <copy todir="${classes.dir}"> </p><p> <fileset dir="${src.dir}" excludes="**/*.java" /> </p><p> </copy> </p><p> <!-- resources --> </p><p> <copy todir="${classes.dir}"> </p><p> <fileset dir="${temporary.dir}/${projectName}/config"/> </p><p> </copy> </p><p> </target> </p><p> </p><p> <!-- create the war --> </p><p> <target name="web-war" depends="compile" description="create war"> </p><p> </p><p> </p><p> </p><p> <war destfile="${builder.dir}/../${projectName}.war" webxml="${WebRoot.dir}/WEB-INF/web.xml"> </p><p> <fileset dir="${WebRoot.dir}"> </p><p> </fileset> </p><p> </war> </p><p> </target> </p><p> </p><p> <!-- create the ear --> </p><p> <target name="ear" depends="web-war" description="create ear"> </p><p> <!-- </p><p> <ear destfile="${builder.dir}/../${projectName}.ear" </p><p> appxml="${basedir}/META-INF/META-INF/application.xml" </p><p> duplicate="preserve"> </p><p> <fileset dir="${basedir}/META-INF" includes="**/*.*" /> </p><p> <fileset dir="${builder.dir}/.."> </p><p> <include name="${projectName}.war" /> </p><p> </fileset> </p><p> </ear> </p><p> --> </p><p> </target> </p><p> </p><p> <target name="deploy" depends="ear"> </p><p> <echo>+ ===================================================== +</echo> </p><p> <echo>+ +</echo> </p><p> <echo>+ Building Complete, Cleaning Temporary Files...... +</echo> </p><p> <echo>+ +</echo> </p><p> <echo>+ ===================================================== +</echo> </p><p> <delete dir="${builder.dir}"> </p><p> </delete> </p><p> </target> </p><p> </p><p> </project> </p><p>
</p><p>bat :</p><p>
</p><p>[java] view plain copy</p><p>@echo off </p><p>del deploy.log </p><p>call ant -f ./deploy.xml -debug -l deploy.log </p>
复制代码
start deploy.log
OK ,搞定!
作者:
china-bobi
时间:
2018-6-17 11:45
虽然现在还看不懂,但是觉得应该很牛逼
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2