主要通过Ant实现,需要用到svnant等jar包。
要实现ant可以从svn服务器上检出代码要使用svnant jar文件。
从网上下载svnant 包,下载地址:
http://subclipse.tigris.org/files/documents/906/49042/svnant-1.3.1.zip
主要有两个文件,build.xml及build.properties。
build.xml为checkou代码、编译、打包、部署的Ant运行脚步。
<project basedir="." name="${work.space}" default="auto">
<!-- 所有的参数都在build.properties文件 -->
<property file="build.properties" />
<!--svnant支持库-->
<path id="svnant.lib">
<pathelement location="./apache-ant/lib/svnjavahl.jar" />
<pathelement location="./apache-ant/lib/svnant.jar" />
<pathelement location="./apache-ant/lib/svnClientAdapter.jar" />
</path>
<!--项目的classpath库 -->
<path id="project.classpath">
<pathelement location="./${work.space}/WebContent/WEB-INF/classes" />
<fileset dir="./${work.space}/WebContent/WEB-INF/lib" />
</path>
<!-- load the svn task -->
<taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="svnant.lib" />
<!--svn同步任务-->
<target name="svn">
<echo message="======svn checkout======" />
<mkdir dir="./${work.space}"/>
<svn username="${svn.username}" password="${svn.password}" javahl="false">
<checkout url="${svn.url}" destPath="./${work.space}" />
</svn>
</target>
<!--编译-->
<target name="compile" depends="svn">
<echo message="compile==========>./${work.space}: ${ant.file}" />
<mkdir dir="./${work.space}/WebContent/WEB-INF/classes" />
<copy todir="./${work.space}/WebContent/WEB-INF/classes">
<fileset dir="./${work.space}/src" excludes="**/*.launch, **/*.java, config/*.*"/>
</copy>
<javac includeantruntime="on" debug="true" debuglevel="source,lines" destdir="./${work.space}/WebContent/WEB-INF/classes" source="1.7" target="1.7" encoding="utf-8">
<src path="./${work.space}/src" />
<classpath>
<path refid="project.classpath">
</path>
</classpath>
</javac>
</target>
<!--压缩,打包-->
<target name="war" depends="compile">
<echo message="======compress j2ee war file======" />
<mkdir dir="./${work.space}" />
<war destfile="./${work.space}/${work.space}.war" webxml="./${work.space}/WebContent/WEB-INF/web.xml">
<fileset dir="./${work.space}/WebContent" />
<classes dir="./${work.space}/WebContent/WEB-INF/classes" />
<lib dir="./${work.space}/WebContent/WEB-INF/lib" />
</war>
</target>
<!--关闭resin-->
<target name="shutdown_resin">
<echo message="======shutdown resin======" />
<exec executable="${resin.home}/bin/resin.sh" failonerror="false">
<arg value="shutdown"/>
</exec>
<sleep seconds="10"/>
</target>
<!--清理resin下面之前部署的项目 -->
<target name="clear" depends="shutdown_resin">
<echo message="======clear======" />
<!--<delete dir="${resin.home}/work/Catalina/localhost/${work.space}" />-->
<delete dir="${resin.home}/webapps/${work.space}" />
<delete file="${resin.home}/webapps/${work.space}.war" />
</target>
<!--把项目war包复制到resin/webapps-->
<target name="deploy" depends="clear">
<echo message="======deploy======" />
<copy file="./${work.space}/${work.space}.war" todir="${resin.home}/webapps" />
</target>
<!--启动resin-->
<target name="startup_resin" depends="deploy">
<echo message="======startup resin======" />
<sleep seconds="5"/>
<exec executable="${resin.home}/bin/resin.sh" failonerror="false">
<arg value="start"/>
</exec>
</target>
<!--svn checkout代码,编译打包war,关闭resin,删除原有发布的工程,部署,启动resin,-->
<target name="auto" depends="war,startup_resin">
<echo message="Auto deploy done!!!!" />
</target>
</project>
#自动发布的项目名
work.space=demo
#resin服务器所在路径
resin.home=/usr/local/app/resin/
#自动checkout的svn路径
svn.url=svn://113.108.221.228/demo
#自动checkout的svn账号
svn.username=test
#自动checkout的svn账号密码
svn.password=test1234

本文详细介绍了如何使用Ant和svnant jar文件从SVN服务器检出代码,并自动完成编译、打包、部署整个流程。包括配置build.xml和build.properties文件,实现自动化部署。
1370

被折叠的 条评论
为什么被折叠?



