项目打包脚本

    记录一个ant脚本,可以把项目classes打成jar,在放在工程的lib下,然后部署到服务器。以后改了代码只用再打成jar包,然后替换jar就行。 

<?xml version="1.0" encoding="UTF-8"?>
<project name="kyle1970" default="unzip">

    <property name="src" location="src" />
    <property name="webroot" location="WebRoot" />

    <property name="lib.dir" location="WebRoot/WEB-INF/lib" />
    <property name="build.dir" location="build" />
    <property name="class.dir" location="${build.dir}/WEB-INF/classes" />
    <property name="war" location="${build.dir}/${ant.project.name}.war" />
    <!--生成war到-->
    <property name="tomcat.home" location="D:apache-tomcat-7.0.29" />

    <path id="compile.lib">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <target name="clean">
        <deltree dir="${build.dir}" />
    </target>

    <target name="prepare" depends="clean">
        <echo>
                #########################################
                # prepare, create build dirs... #
                #########################################
            </echo>
        <mkdir dir="${build.dir}" />
    </target>


    <target name="compile" depends="prepare">
        <echo>
                    #######################################
                    # compile ..                          #
                    #######################################
            </echo>
        <mkdir dir="${class.dir}" />
        <javac encoding="UTF-8" source="1.6" target="1.6" srcdir="${src}" destdir="${class.dir}" debug="on" includeantruntime="false" nowarn="true">
            <compilerarg line="-encoding UTF-8" />
            <classpath>
                <path refid="compile.lib" />
            </classpath>
        </javac>
    </target>



    <target name="generwar" depends="compile">
        <echo>
                    #######################################
                    #                 war                 #
                    #######################################
            </echo>
        <copy todir="${build.dir}">
            <fileset dir="${webroot}">
                <exclude name="**/WEB-INF/classes/test.txt" />
                <exclude name="**/WEB-INF/app_conf_test.txt" />
                <exclude name="**/WEB-INF/lib/ant.jar" />
                <exclude name="**/WEB-INF/lib/jetty_server_*.jar" />
                <include name="**/*" />
            </fileset>
        </copy>

        <war destfile="${war}" webxml="${build.dir}/WEB-INF/web.xml">
            <fileset dir="${build.dir}" />
        </war>
    </target>

     <target name="fabu" depends="generwar" description="部署工程">
         <echo>
                   #######################################
                   #                 fabu                #
                   #######################################
                     </echo>
      <copy file="${war}" todir="${tomcat.home}/webapps" />
      </target>

    <target name="zip" depends="compile">
        <echo>
                    #######################################
                    #                 zip                 #
                    #######################################
        </echo>
        <copy todir="${build.dir}">
            <fileset dir="${webroot}">
                <exclude name="**/WEB-INF/classes/url-test.txt" />
                <exclude name="**/WEB-INF/app_conf_test.txt" />
                <exclude name="**/WEB-INF/lib/ant.jar" />
                <exclude name="**/WEB-INF/lib/jetty_server_6.1.26.jar" />
                <include name="**/*" />
            </fileset>
        </copy>
        <tar destfile="${build.dir}/${ant.project.name}.tar" basedir="${build.dir}"/>
        <!--<gzip src="${build.dir}/${ant.project.name}.tar" zipfile="${build.dir}/${ant.project.name}.tar.gz"/>-->
    </target>
    
     <target name="unzip" depends="zip" description="传到tomcat解压">
        <echo>
                       #######################################
                       #           unzip to tomcat           #
                       #######################################
                         </echo>
        <copy file="${build.dir}/${ant.project.name}.tar" todir="${tomcat.home}/webapps" />
         <!--<unzip src="${tomcat.home}/webapps/${ant.project.name}.tar.gz" dest="${tomcat.home}/webapps"></unzip>-->
         <untar src="${tomcat.home}/webapps/${ant.project.name}.tar" dest="${tomcat.home}/webapps/${ant.project.name}"/>
    </target>
    

</project>
原文地址:https://www.cnblogs.com/zhongkaiuu/p/ant.html