• 使用ant打web应用更新包


       相信很多人也遇到过这样的问题,测试人员认为每次更新包包含的文件越多,项目的风险的就越大,因此每次都让我们开发打每轮修改后更新包。以前都是靠手工整理这些修改的文件,然后合包!不过这样真的费时费力。后来通过在网上搜索和自己整理,最后终于成功实现了脚本,可以自动打更新包。每次只需要设置上次打包的时间和当前时间就可以了。脚本如下:

        <project basedir="." default="usage" name="xiangmu">


    <target name="init">
    <property name="Name" value="xiangmu" />
    <property name="name" value="lingfan" />
    <property name="version" value="1.7.0.0" />
    <property name="year" value="2013" />
    <echo message="----------- ${Name} ${version} [${year}] ------------" />
    <property name="debug" value="on" />
    <property name="optimize" value="on" />
    <property name="deprecation" value="on" />
    <!--上次打包日期-->
    <property name="modifyDate" value="2013-05-06"/>
    <!--打包日期-->
    <property name="Today" value="2013_05_13"/>
    <!--<property name="mycedatasycn.location" value="D:/project/myce/mycedatasycn" />-->


    <!--    java源文件路径 -->
    <property name="src.dir" value="${basedir}/src" />
    <!--    准备webapp文件路径(全部文件) -->
    <property name="buildwar.destAll" value="${basedir}/AntBuild/All" />
    <!--    jar包路径 -->
    <property name="lib.dir" value="${basedir}/WebRoot/WEB-INF/lib" />
    <!--    webapp路径 -->
    <property name="webapp.dir" value="${basedir}/WebRoot" />
    <property name="packages" value="cn.*" />
    <!--    准备源文件路径 -->
    <property name="build.src" value="${basedir}/AntBuild/build" />
    <!--    编译源文件路径 -->
    <property name="build.dest" value="${basedir}/AntBuild/bin" />
    <!--    准备webapp文件路径 -->
    <property name="buildwar.dest" value="${basedir}/AntBuild/warsrc" />

    <!--    准备javadoc文件路径 -->
    <property name="build.javadocs" value="${basedir}/AntBuild/doc" />
    <!--    打包jar文件路径 -->
    <property name="jar.dest" value="${basedir}/AntBuild/jar" />
    <!--    打包war文件路径 -->
    <property name="war.dest" value="${basedir}/AntBuild/war" />
    <!--    resin-home路径 -->
    <property name="resin.home" value="C:\webserver\resin-pro-3.1.6" />


    <property name="j2eelib.dir"
    value="C:\Program Files (x86)\MyEclipse 6.6\myeclipse\eclipse\plugins\com.genuitec.eclipse.j2eedt.core_6.6.0.zmyeclipse660200810\data\libraryset\EE_5" />


    <!--    classpath -->
    <path id="classpath">
    <fileset dir="${j2eelib.dir}">
    <include name="**/*.jar" />
    </fileset>
    <fileset dir="${lib.dir}">
    <include name="**/*.jar" />
    </fileset>
    </path>


    <filter token="year" value="${year}" />
    <filter token="version" value="${version}" />
    <filter token="date" value="${TODAY}" />
    <filter token="log" value="true" />
    <filter token="verbose" value="true" />


    </target>






    <!-- =================================================================== -->
    <!-- Help on usage -->
    <!-- =================================================================== -->
    <target name="usage" depends="init">
    <echo message="${Name} Build file" />
    <echo
    message="-------------------------------------------------------------" />
    <echo message="" />
    <echo message=" available targets are:" />
    <echo message="" />
    <echo message=" jar --> generates the ${name}.jar file" />
    <echo message=" build --> compiles the source code" />
    <echo message=" javadoc --> generates the API documentation" />
    <echo message=" clean --> cleans up the directory" />
    <echo message="" />
    <echo
    message=" Please rename build.properties.default to build.properties" />
    <echo
    message=" and edit build.properties to specify JSDK 2.3 classpath." />
    <echo message="" />
    <echo
    message=" See the comments inside the build.xml file for more details." />
    <echo
    message="-------------------------------------------------------------" />
    <echo message="" />
    <echo message="" />
    </target>






    <!-- =================================================================== -->
    <!-- 准备源文件-->
    <!-- =================================================================== -->
    <target name="prepare-src" depends="init">
    <!-- create directories -->
    <mkdir dir="${build.src}" />
    <mkdir dir="${build.dest}" />
    <mkdir dir="${jar.dest}" />
    <mkdir dir="${war.dest}" />
    <mkdir dir="${buildwar.dest}/${Name}" />
    <mkdir dir="${buildwar.dest}/${Name}/WEB-INF/classes" />
    <mkdir dir="${buildwar.destAll}/${Name}"/>
    <mkdir dir="${buildwar.destAll}/${Name}/WEB-INF/classes"/>
    <!-- copy src files -->
    <copy todir="${build.src}"  includeemptydirs="false" overwrite="true">
    <fileset dir="${src.dir}" >
    <date pattern="yyyy-MM-dd" datetime="${modifyDate}" when="after"/>
    </fileset>
    </copy>
    <copy todir="${buildwar.dest}/${Name}"  includeemptydirs="false" overwrite="true">
    <fileset dir="${webapp.dir}" >
    <exclude name="**/*html5*/**"/>
    <exclude name="**/*monitor*/**"/>
    <exclude name="**/*.class"/>
    <date pattern="yyyy-MM-dd" datetime="${modifyDate}" when="after"/>
    </fileset>
    </copy>
    <copy todir="${buildwar.destAll}/${Name}"  includeemptydirs="false" overwrite="true">
    <fileset dir="${webapp.dir}" >
    <exclude name="**/*monitor*/**"/>
    </fileset>
    </copy>
    </target>


    <!-- =================================================================== -->
    <!-- 编译源文件,所有的文件,用于更新包  -->
    <!-- =================================================================== -->
    <target name="buildAll" depends="prepare-src">
    <javac srcdir="${src.dir}"
    destdir="${buildwar.destAll}/${Name}/WEB-INF/classes" debug="${debug}" encoding="UTF-8"
    optimize="${optimize}">
    <classpath refid="classpath" />
    </javac>
    <copy todir="${buildwar.destAll}/${Name}/WEB-INF/classes"  includeemptydirs="false" overwrite="true">
    <fileset dir="${src.dir}">
    <include name="**/*.xml" />
    </fileset>
    </copy>
    </target>


    <!-- =================================================================== -->
    <!-- 编译源文件,更新包-->
    <!-- =================================================================== -->
    <target name="buildUpdate" depends="buildAll">
    <javac srcdir="${build.src}"
    destdir="${buildwar.dest}/${Name}/WEB-INF/classes" debug="${debug}" encoding="UTF-8" 
    optimize="${optimize}">
    <classpath>
    <path refid="classpath" />
    <pathelement path="${buildwar.destAll}/${Name}/WEB-INF/classes"/>
    </classpath>
    </javac>
    <copy todir="${buildwar.dest}/${Name}/WEB-INF/classes"  includeemptydirs="false" overwrite="true">
    <fileset dir="${build.src}">
    <include name="**/*.xml" />
    <date pattern="yyyy-MM-dd" datetime="${modifyDate}" when="after"/>
    </fileset>
    </copy>
    </target>






    <!-- =================================================================== -->
    <!-- 打war包 更新包-->
    <!-- =================================================================== -->


    <target name="war" depends="clean,buildUpdate">
    <war warfile="${war.dest}/${Name}.war" needxmlfile="false"   >
    <fileset dir="${buildwar.dest}/${Name}"> 
    </fileset>
    </war>


    </target>


    <!-- =================================================================== -->
    <!-- 清除临时文件-->
    <!-- =================================================================== -->
    <target name="clean" depends="init">
    <delete dir="${build.src}" />
    <delete dir="${build.dest}" />
    <delete dir="${buildwar.dest}" />
    <delete dir="${war.dest}" />
    <delete dir="${buildwar.destAll}" />
    </target>


    </project>

  • 相关阅读:
    防止重复点击
    刷新当前页面的几种方法
    PHP删除数组中空值
    json转化数组
    两个不能同时共存的条件orWhere查询
    SQLSTATE[42000]
    laravel一个页面两个表格分页处理
    Hash::make与Hash::check
    unbind()清除指定元素绑定效果
    二级联动
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3091520.html
Copyright © 2020-2023  润新知