自动获取svn代码并且编译发布

自动获取svn代码并且编译发布  

主要分几个步骤

步骤一:让ant支持从svn获取源代码

我们去subclipse网站的svnant项目下载所需包,注意subversion与svnant的版本统一的问题,直接将下载下来的zip包中的jar拷贝到ant的lib目录下

步骤二:写ant脚本

在ant脚本中主要加入了获取代码的脚本,如下:

<svn username="myname" password="mypwd" javahl="false">
            <checkout url="${urlRepos}" destPath="${work.space}"/>
</svn>

下面脚本(build.xml)中的j2ee1.4lib大家可直接指向应用服务器的lib包,即可编译

步骤三:编译发布,以root身份直接ant 即可。

 

附上从网上抄来的脚本:

1、build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="cyntv20" default="auto">
    <!-- all properties are in build.properties -->
    <property file="${basedir}/build.properties"/>
    <!--svn本身需要的运行库 -->
    <path id="svnant.lib">
        <pathelement location="${svnjavahl.jar}"/>
        <pathelement location="${svnant.jar}"/>
        <pathelement location="${svnClientAdapter.jar}"/>
    </path>
    <!--java EE 1.4 库 -->
   <path id="javaEE1.4">
        <fileset dir="${javaEE1.4.lib}">
            <include name="**/*.jar"/>
        </fileset>
    </path>
    <!--项目的classpath库 -->
    <path id="project.classpath">
        <pathelement location="${build.dir}"/>
        <fileset dir="${lib.dir}"/>
    </path>
    <!--清理项目任务(干掉下载目录,tomcat原来的部署文件) -->
    <target name="clear">
        <delete dir="${work.space}"/>
        <delete dir="${tomcat.home}/work/Catalina/localhost/${ant.project.name}"/>
        <delete dir="${tomcat.home}/webapps/${ant.project.name}"/>
        <delete dir="${tomcat.home}/webapps/${ant.project.name}.war"/>
    </target>
    <!-- load the svn task -->
    <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="svnant.lib"/>
    <!--svn同步任务-->
    <target name="svn" depends="clear">
        <mkdir dir="${work.space}"/>
        <svn username="myname" password="mypwd" javahl="false">
            <checkout url="${urlRepos}" destPath="${work.space}"/>
        </svn>
    </target>
    <!--编译-->
    <target name="compile"   description="======compile project======">
        <echo message="compile==========>${ant.project.name}: ${ant.file}"/>
        <mkdir dir="${build.dir}"/>
        <copy includeemptydirs="false" todir="${build.dir}">
            <fileset dir="${java.source}" excludes="**/*.launch, **/*.java"/>
        </copy>
        <!--<copy includeemptydirs="false" todir="${build.dir}">
            <fileset dir="${java.config}" excludes="**/*.launch, **/*.java"/>
        </copy>-->
        <javac includejavaruntime="true" debug="true" debuglevel="${debuglevel}" destdir="${build.dir}"
               source="${source}" target="${target}" encoding="GBK">
            <src path="${java.source}"/>
            <!--<exclude name="config/"/>-->
            <classpath>
                <path refid="project.classpath">
                </path>
              <path refid="javaEE1.4">
            </classpath>
        </javac>
        <!--<javac debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" source="${source}" target="${target}"
               encoding="utf-8">
            <src path="${java.config}"/>
        </javac>-->
    </target>
    <!--压缩,打包-->
    <target name="war" depends="compile" description="======compress j2ee war file======">
        <mkdir dir="${dist.dir}"/>
        <!--compress j2ee war file-->
        <war destfile="${war.file}" webxml="${web.dir}/WEB-INF/web.xml">
            <fileset dir="${web.dir}"/>
            <classes dir="${build.dir}"/>
            <lib dir="${lib.dir}"/>
        </war>
    </target>
    <!--shutdowntomcat-->
    <target name="shutdowntomcat" description="========shutdowntomcat===========">
        <exec executable="${tomcat.home}/bin/shutdown.sh" failοnerrοr="false"></exec>
        <sleep seconds="10"/>
    </target>
    <!--startuptomcat-->
    <target name="startuptomcat" description="========startuptomcat===========">
        <sleep seconds="5"/>
        <exec executable="${tomcat.home}/bin/startup.sh" failοnerrοr="false"></exec>
    </target>
    <!--部署到tomcat下面克-->
    <target name="deploy" depends="war">
        <copy file="${war.file}" todir="${tomcat.home}/webapps"/>
    </target>
    <!--全自动无敌部署,启动关闭tomcat-->
    <target name="auto" depends="shutdowntomcat,deploy,startuptomcat">
        <echo message="DONE!!!!"/>
    </target>
</project>

 

2、build.properties

tomcat.home =E:/dev/apache-tomcat-6.0.29


build.version=1.0.0

svnant.jar=D:/ant1.8/lib/svnant.jar
svnClientAdapter.jar=D:/ant1.8/lib/svnClientAdapter.jar
svnjavahl.jar=D:/ant1.8/lib/svnjavahl.jar
javaEE1.4.lib=D:/ant1.8/lib

debuglevel=source,lines
target=1.6
source=1.6

work.space=D:/ant1.8/cyntv/allsource
dist.dir=${work.space}

build.dir=${work.space}/WebRoot/WEB-INF/classes
lib.dir=${work.space}/WebRoot/WEB-INF/lib

java.source=${work.space}/src
#java.config=${work.space}/src/config

web.dir=${work.space}/WebRoot
#resource.dir=${work.space}/resources

war.file=${dist.dir}/${ant.project.name}.war

urlRepos=svn://52.24.32.195/var/svn/svntest/code/test2.0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值