JAVAWEB项目自动打包部署脚本(SVN+ANT)

acts_meeting_build.xml 脚本:

<?xml version="1.0" encoding="utf-8"?>

<project name="acts_meeting" basedir="/home/svnData/acts_meeting" default="all">
    <property name="tomcat" value="tomcat8_app"/>
    <property file="/home/svnPublish/build.properties" />
    <property name="webapp" value="acts_meeting" />
    <!--svnant支持库-->
    <path id="svnant.lib">
        <pathelement location="${svnant.jar}" />
        <pathelement location="${svnant.jar}" />
        <pathelement location="${svnClientAdapter.jar}" />
    </path>
    <!-- load the svn task -->
    <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="svnant.lib" />

    <!--svn同步任务-->
    <target name="svn">
        <svn username="${svn.username}" password="${svn.password}" javahl="false">
            <!-- 检出代码 这里使用 export 不是checkout 二者区别 checkout会svn相关信息文件检出,export只是检出最新的文件-->
            <checkout  url="svn://192.168.1.180/acts_sign/trunk/${webapp}" destPath="${svn.home}/${webapp}" />
        </svn>
    </target>
    <!--项目打包-->
    <path id="classpath">
        <fileset dir="./WebRoot/WEB-INF/lib">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <target name="prepare" description="prepare ">
        <mkdir dir="dist/tmp" />
        <mkdir dir="dist/module" />
        <mkdir dir="dist/war" />
    </target>

    <target name="jar-web" description="web jar">
        <delete file="dist/war/${webapp}-web.jar" />
        <echo message="开始编译项目源码" />
        <javac srcdir="src/java" includes="com/acts/web/**/*.*,com/acts/web/**/**/*.*" debug="true" fork="yes" destdir="dist/tmp" classpathref="classpath" encoding="UTF-8" includeantruntime="on"/>
        <jar destfile="dist/war/${webapp}-web.jar" update="true">
            <fileset dir="dist/tmp" includes="**/*.*" />
        </jar>
        <echo message="开始拷贝资源文件" />
        <copy todir="WebRoot/WEB-INF/classes">
            <fileset dir="src/java" includes="com/acts/web/**/*.xml*,com/acts/web/**/**/*.xml*">
            </fileset>
            <fileset dir="src/resource" includes="**/*.*">
            </fileset>
        </copy>
    </target>

    <target name="war" description="war ${webapp}" depends="jar-web">
        
        <echo message="开始打包" />
        <delete file="dist/war/${webapp}.war" />
        <copy todir="WebRoot/WEB-INF/lib">
            <fileset dir="dist/war"/>
        </copy>
        <war warfile="dist/war/${webapp}.war"
                includes="**/*.*"
                excludes="WEB-INF/classes/**/*.class"
                webxml="WebRoot/WEB-INF/web.xml" 
                update="true" 
                basedir="WebRoot"/>
        
        <echo message="删除临时文件" />
        <delete file="WebRoot/WEB-INF/lib/${webapp}-web.jar" />    
        <delete file="WebRoot/WEB-INF/classes" />
    </target>
    <echo message="开始部署" />
    <target name="publish"> 
         <exec executable="/home/svnPublish/publish.sh" failonerror="true">
              <arg value="/home/apache-tomcat/${tomcat}/"/>
              <arg value="${webapp}"/>
         </exec> 
    </target> 
    <target name="all"  depends="svn,prepare, jar-web, war,publish">
    </target>
</project>

build.properties 配置:

build.version=1.0.0
svnant.jar=/usr/local/apache-ant-1.9.2/lib/svnant.jar
svnClientAdapter.jar=/usr/local/apache-ant-1.9.2/lib/svnClientAdapter.jar
svnjavahl.jar=/usr/local/apache-ant-1.9.2/lib/svnjavahl.jar
increment.jar=/usr/local/apache-ant-1.9.2/lib/increment.export.jar
svn.username=zhangzhipeng
svn.password=zhangzhipeng
svn.home=/home/svnData
爪哇笔记

作者: 小柒

出处: https://blog.52itstyle.vip

分享是快乐的,也见证了个人成长历程,文章大多都是工作经验总结以及平时学习积累,基于自身认知不足之处在所难免,也请大家指正,共同进步。

本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 如有问题, 可邮件(345849402@qq.com)咨询。