使用ant进行web打包

今天学习了使用ant进行打包,记录如下:

<project name="platform-war" default="release" basedir=".">

    <property file="${resource.home}/database.conf.properties" />

    <!-- ==================== File and Directory Names ======================== -->

    <property name="build.home" value="${basedir}/target/build" />
    <property name="dist.home" value="${basedir}/target/dist" />
    <property name="deploy.path" value="${dist.home}/platform" />

    <property name="src.home" value="${basedir}/src/main/java" />
    <property name="resource.home" value="${basedir}/src/main/resources" />
    <property name="web.home" value="${basedir}/src/main/webapp" />
    <property name="lib.compile.home" value="${basedir}/antlib" />
    <property name="lib.runtime.home" value="${web.home}/WEB-INF/lib" />

    <tstamp prefix="build">
        <format property="dt" pattern="yyyyMMdd.HHmmss.SSS" />
    </tstamp>

    <tstamp>
        <format property="deploy.debug.tstamp" pattern="yyyy-MM-dd HH:mm:ss" />
    </tstamp>
    <echo>开始打包:${deploy.debug.tstamp}</echo>

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

    <target name="-clean-compile" description="清除编译过的文件和发布的文件">
        <delete dir="${build.home}" />
        <delete dir="${dist.home}" />
    </target>


    <target name="clean" depends="-clean-compile" description="深层清除发布环境,删除所有预编译文件,以重新编译所有Java类和重新复制所有文件">
    </target>


    <target name="-prepare" description="为发布工作进行准备">

        <mkdir dir="${build.home}/java" />
        <mkdir dir="${build.home}/classes" />
        <mkdir dir="${dist.home}" />

    </target>

    <target name="-compile" depends="-prepare" description="">
        <tstamp>
            <format property="deploy.debug.tstampcompile" pattern="yyyy-MM-dd HH:mm:ss" />
        </tstamp>
        <echo>开始正在编译java:${deploy.debug.tstampcompile}</echo>
        <copy todir="${build.home}/java" preservelastmodified="true" encoding="UTF-8" outputencoding="UTF-8">
            <fileset dir="${src.home}">
                <include name="**/*.java" />
                <exclude name="**/CVS/" />
                <exclude name="**/SVN/" />
            </fileset>
        </copy>
        <javac srcdir="${build.home}/java" destdir="${build.home}/classes" nowarn="true" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}" encoding="UTF-8" source="1.7" target="1.7">
            <classpath refid="compile.web.classpath" />
        </javac>

    </target>


    <target name="compile" depends="-compile" description="编译需要的Java类(增量),并直接将编译后的结果复制(仅更新文件)到发布路径">

    </target>


    <target name="copy-web" description="发布Web内容到发布目录(仅更新文件)">
        <tstamp>
            <format property="deploy.debug.tstampcopyweb" pattern="yyyy-MM-dd HH:mm:ss" />
        </tstamp>
        <echo>开始copyweb:${deploy.debug.tstampcopyweb}</echo>
        <copy todir="${deploy.path}" preservelastmodified="true">
            <fileset dir="${web.home}">
            </fileset>
        </copy>

        <copy todir="${deploy.path}/WEB-INF/classes" includeEmptyDirs="false">
            <fileset dir="${build.home}/classes">
            </fileset>
            <fileset dir="${resource.home}">
            </fileset>
        </copy>
    </target>

    <target name="release" depends="-clean-compile,-prepare,compile,copy-web" description="打包成war">
        <tstamp>
            <format property="deploy.debug.tstamprelease" pattern="yyyy-MM-dd HH:mm:ss" />
        </tstamp>
        <echo>开始打包war:${deploy.debug.tstamprelease}</echo>
        <war destfile="${dist.home}/platform.war">
            <fileset dir="${dist.home}/platform">
            </fileset>
        </war>
        <tstamp>
            <format property="deploy.debug.tstampover" pattern="yyyy-MM-dd HH:mm:ss" />
        </tstamp>
        <echo>结束打包:${deploy.debug.tstampover}</echo>
    </target>
</project>


 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值