• Ant的使用(一)


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

    <project name="projectName" default="zip" basedir=".">

    <target name="setvar"> 变量的设定

    <property name="build" value="build"/>

    <property name="buildClass" value="${build}/classes"/>

    <property name="buildDist" value="${build}/dist"/>

    <property name="buildDistLib" value="${buildDist}/lib"/>

    <property name="module" value="testModule"/>

    <property name="lib" value="lib"/>

    <property name="lastvalidatetime" value="lastvalidatetime"/>

    <property name="src" value="src"/>

    <path id="my-class-path"> //设置path变量

    <fileset dir="${lib}" includes="*.jar"/>

    </path>

    <tstamp> //设置运行的时间戳变量

    <format property="today" pattern="MM/dd/yyyy hh:mm aa" locale="en"/>

    <format property="time" pattern="yyyyMMdd_HHmmss" locale="en"/>

    <format property="date" pattern="yyyyMMdd" locale="en"/>

    </tstamp>

    <property name="timestamp" value="${time}"/>

    <property file="build.properties"/>//引入property文件,之后可以用里面的key获取value,如:build.version=4.0

    <property name="build.name" value="${module}_v${build.version}_${date}"/>

    <property name="versionPath" value="/version"/>

    </target>

    <target name="clean" depends="setvar">

    <delete dir="${build}"/>//删除build文件夹

    <mkdir dir="${build}"/>//创建 build文件夹

    <mkdir dir="${buildClass}"/>//创建build/classes文件夹

    <mkdir dir="${buildDist}"/>//创建build/dist文件夹

    <mkdir dir="${buildDistLib}"/>创建build/dist/lib文件夹

    </target>

    <target name="compile-classes" depends="clean"> //编译,依赖clean

        //http://ant.apache.org/manual/Tasks/javac.html

        //必须要有srcdir,除非有内嵌的<src>

    <javac debug="on" deprecation="on" includeantruntime="false" source="1.6" target="1.6" destdir="${buildClass}"> //编译到build/classes

    <classpath>//The classpath to use.需要依赖哪些包时

    <path refid="my-class-path"/>

    </classpath>

    <src path="${src}"/>

    </javac>

    </target>

    <target name="jar" depends="compile-classes">//打包jar

    <jar jarfile="${build}/${module}.jar" basedir="${buildClass}"> //将编译出build/classes的class打包为build estModule.jar

    <manifest/>

    </jar>

    </target>

    <target name="work" depends="jar">

    <copy todir="${buildDistLib}">//复制文件到build/dist/lib

    <fileset dir="${lib}" includes="*.jar"/> //复制文件${lib}下所有jar文件到${buildDistLib}

    <fileset dir="${build}" includes="${module}.jar"/> //复制文件${build}下testModule.jar文件到${buildDistLib}

    </copy>

    <copy todir="${buildDist}">

    <fileset dir="./" includes="*.bat,lastsynctime/*,deviceType/*,"/>//复制当前目录去.bat...到${buildDist}

    </copy>

    <copy todir="${buildDist}/config.default">//复制config目录去${buildDist}/config.default目录

    <fileset dir="config" includes="**"/>

    </copy>

    <copy todir="${buildDist}" file="README.md" />

    <copy todir="${buildDist}" file="init.sql" />

    <copy todir="${buildDist}" file="curlTool.rar" />

    <delete dir="${buildClass}"/>

    <delete file="${build}/${module}.jar"/>

    <property name="versionFolder" value="${buildDist}/${versionPath}"/>

    <delete dir="${versionFolder}"/>

    <mkdir dir="${versionFolder}"/>//创建${buildDist}/${versionPath}文件夹

    <property name="fileName" value="${versionFolder}/${build.name}.txt"/>

    <echo message="** Build Information ** ${line.separator}" file="${fileName}"/> //将显示信息输入到文件${fileName}换行

    <echo message="Version: ${build.version}${line.separator}" file="${fileName}" append="true"/>//将显示信息输入追加到文件${fileName}换行

    <echo message="Build Time: ${timestamp}${line.separator}" file="${fileName}" append="true"/>

    <echo message="Java Version: ${java.runtime.version}${line.separator}" file="${fileName}" append="true"/>

    <!-- MD5 info-->

    <echo message="--- md5 info ---${line.separator}" file="${fileName}" append="true"/>

    <checksum file="${buildDist}/${lib}/test1.jar" property="test1MD5"/> //check MD5 test1.jar 到test1MD5

    <echo message="test1.jar:${test1MD5}${line.separator}" file="${fileName}" append="true"/> 

    <checksum file="${buildDist}/${lib}/${module}.jar" property="test2MD5"/>

    <echo message="${module}.jar:${test2MD5}${line.separator}" file="${fileName}" append="true"/>

    </target>

    <target name="zip" depends="work">

    <zip destfile="${build}/${module}.zip" basedir="${buildDist}"/> //将${buildDist}打包为${build}/${module}.zip

    </target>

    </project>

  • 相关阅读:
    iframe标签用法详解
    Redis 数据备份与恢复,安全,性能测试,客户端连接,管道技术,分区(四)
    Redis 有序集合(sorted set),发布订阅,事务,脚本,连接,服务器(三)
    Redis 命令,键(key),字符串(String),哈希(Hash),列表(List),集合(Set)(二)
    Redis 安装,配置,简介,数据类型(一)
    Python2.x与3​​.x版本区别
    Python主流框架
    python面向对象( item系列,__enter__ 和__exit__,__call__方法,元类)
    Json对象与Json字符串互转(4种转换方式)
    JSON.parse和eval的区别
  • 原文地址:https://www.cnblogs.com/daxiong225/p/9601652.html
Copyright © 2020-2023  润新知