基础basic.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <property file="build.properties"/>

<property name="src.dir" location="src"/>
    <property name="test.src.dir" location="test"/>
    <property name="web.dir" location="web"/>
    <property name="sql.dir" location="sql"/>

<property name="web.WEB-INF.dir" location="${web.dir}/WEB-INF"/>
    <property name="lib.dir" location="${web.WEB-INF.dir}/lib"/>
    <property name="run.test.className" value="**/Test*.class"/>

<property name="build.dir" location="build"/>
    <property name="build.src.dir" location="${build.dir}/src"/>
    <property name="build.src.classes.dir" location="${build.dir}/classes"/>
    <property name="build.test.dir" location="${build.dir}/test"/>
    <property name="build.test.src.dir" location="${build.test.dir}/src"/>
    <property name="build.test.classes.dir" location="${build.test.dir}/classes"/>
    <property name="build.test.report" location="${build.test.dir}/report"/>
    <property name="build.jar.dir" location="${build.dir}/dist"/>
    <property name="build.zip.dir" location="${build.dir}/zip"/>
    <property name="build.doc.dir" location="${build.dir}/doc"/>
    <property name="metadata" location="metadata"/>

<property environment="env"></property>

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

<path id="compile-test-path">
        <path refid="compile-path"/>
        <pathelement location="${build.src.classes.dir}"/>
    </path>

<path id="run-test">
        <path refid="compile-test-path"/>
        <pathelement location="${build.test.classes.dir}"/>
    </path>

<macrodef name="cleanProject">
        <attribute name="cleanDir" default="${build.dir}"/>
        <element name="cleanTask" optional="yes"/>
        <sequential>
            <echo>项目清理</echo>
            <delete dir="@{cleanDir}"/>
            <cleanTask/>
        </sequential>
    </macrodef>

<macrodef name="initDir">
        <attribute name="build.dir" default="${build.dir}"/>
        <attribute name="build.src.dir" default="${build.src.dir}"/>
        <attribute name="build.src.classes.dir" default="${build.src.classes.dir}"/>
        <attribute name="build.test.dir" default="${build.test.dir}"/>
        <attribute name="build.test.src.dir" default="${build.test.src.dir}"/>
        <attribute name="build.test.classes.dir" default="${build.test.classes.dir}"/>
        <attribute name="build.test.report" default="${build.test.report}"/>
        <attribute name="build.jar.dir" default="${build.jar.dir}"/>
        <attribute name="build.zip.dir" default="${build.zip.dir}"/>
        <attribute name="build.doc.dir" default="${build.doc.dir}"/>
        <attribute name="metadata" default="${metadata}"/>

<element name="initTask" optional="yes"/>
        <sequential>
            <echo>项目目录初始化</echo>
            <mkdir dir="@{build.dir}"/>
            <mkdir dir="@{build.src.dir}"/>
            <mkdir dir="@{build.src.classes.dir}"/>
            <mkdir dir="@{build.test.dir}"/>
            <mkdir dir="@{build.test.src.dir}"/>
            <mkdir dir="@{build.test.classes.dir}"/>
            <mkdir dir="@{build.test.report}"/>
            <mkdir dir="@{build.jar.dir}"/>
            <mkdir dir="@{build.zip.dir}"/>
            <mkdir dir="@{build.doc.dir}"/>
            <mkdir dir="@{metadata}"/>
            <initTask/>
        </sequential>
    </macrodef>

<macrodef name="compileSrcFile">
        <attribute name="from.src.dir" default="${src.dir}"/>
        <attribute name="to.dest.dir" default="${build.src.classes.dir}"/>
        <attribute name="class.path.ref" default="compile-path"/>
        <attribute name="failonerror" default="true"/>

<element name="compileTask" optional="yes"/>
        <sequential>
            <echo>编译源文件</echo>
            <javac failonerror="@{failonerror}"
                   includeantruntime="false"
                   srcdir="@{from.src.dir}"
                   destdir="@{to.dest.dir}"
                   classpathref="@{class.path.ref}"/>
            <compileTask/>
        </sequential>
    </macrodef>

<macrodef name="compileTestSrcFile">
        <attribute name="from.test.src.dir" default="${test.src.dir}"/>
        <attribute name="to.test.dest.dir" default="${build.test.classes.dir}"/>
        <attribute name="class.path.ref" default="compile-test-path"/>
        <attribute name="failonerror" default="true"/>
        <element name="compileTestTask" optional="yes"/>
        <sequential>
            <echo>编译测试文件</echo>
            <javac failonerror="@{failonerror}"
                   includeantruntime="false"
                   srcdir="@{from.test.src.dir}"
                   destdir="@{to.test.dest.dir}"
                   classpathref="@{class.path.ref}"/>
            <compileTestTask/>
        </sequential>
    </macrodef>

<macrodef name="runTest">
        <attribute name="printsummary" default="false"/>
        <attribute name="failureproperty" default="junit.fail"/>
        <attribute name="haltonfailure" default="false"/>
        <attribute name="runClasspath" default="run-test"/>
        <attribute name="fork" default="true"/>
        <!-- 命令行输出测试信息 brief主要信息 -->
        <!-- <attribute name="formatter" default="brief" /> -->
        <!--测试类信息格式-->
        <attribute name="formatter" default="xml"/>
        <!--测试类信息使用文件存储-->
        <attribute name="usefile" default="true"/>
        <!--测试类报告输出位置-->
        <attribute name="report.to.dir" default="${build.test.report}"/>
        <!--测试类来自哪个文件夹-->
        <attribute name="from.test.class.dir" default="${build.test.classes.dir}"/>
        <!--测试哪些类-->
        <attribute name="include.run.TestClass" default="${run.test.className}"/>
        <!--从哪个dir中找报告-->
        <attribute name="from.report.dir" default="${build.test.report}"/>
        <!--格式化哪些测试类结果xml文件-->
        <attribute name="report.file" default="TEST-*.xml"/>
        <!--报告采用哪种格式-->
        <attribute name="fortmatType" default="frames"/>
        <!--格式化后报告输出位置-->
        <attribute name="to.dir" default="${build.test.report}/html"/>
        <element name="runTestTask" optional="yes"/>
        <sequential>
            <echo>运行单元测试</echo>
            <junit failureproperty="@{failureproperty}" fork="@{fork}"
                   printsummary="@{printsummary}"
                   haltonfailure="@{haltonfailure}">
                <classpath refid="@{runClasspath}"/>
                <formatter type="@{formatter}" usefile="@{usefile}"/>
                <batchtest todir="@{report.to.dir}">
                    <fileset dir="@{from.test.class.dir}" includes="@{include.run.TestClass}"/>
                </batchtest>
            </junit>
            <echo>生成报告</echo>
            <junitreport todir="@{report.to.dir}">
                <!--从哪个dir中找报告-->
                <fileset dir="@{from.report.dir}" includes="@{report.file}"/>
                <!--格式化好的报告文件输出位置-->
                <report format="@{fortmatType}" todir="@{to.dir}"/>
            </junitreport>
            <fail if="${failureproperty}" message="单元测试失败具体查看${build.test.report}"/>
            <runTestTask/>
        </sequential>
    </macrodef>

<macrodef name="docFiles">
        <attribute name="src.from.dir" default="${src.dir}"/>
        <attribute name="use" default="true"/>
        <attribute name="packagename" default="com.*"/>
        <attribute name="charset" default="UTF-8"/>
        <attribute name="fileEncoding" default="UTF-8"/>
        <attribute name="docEncoding" default="UTF-8"/>
        <attribute name="to.dir" default="${build.doc.dir}"/>
        <attribute name="classpath" default="compile-path"/>
        <element name="docFilesTask" optional="yes"/>

<sequential>
            <echo>生成文档</echo>
            <javadoc sourcepath="@{src.from.dir}"
                     use="@{use}"
                     packagenames="@{packagename}"
                     charset="@{charset}"
                     encoding="@{fileEncoding}"
                     docencoding="@{docEncoding}"
                     destdir="@{to.dir}"
                    >
                <classpath refid="@{classpath}"/>

</javadoc>
            <docFilesTask/>
        </sequential>
    </macrodef>

<macrodef name="jarFile">
        <attribute name="dest" default="${build.jar.dir}/${project.jar.name}"/>
        <attribute name="basedir" default="${build.src.classes.dir}"/>
        <attribute name="buildBy" default="${user.name}"/>
        <attribute name="duplicate" default="preserve"/>
        <attribute name="package" default="null"/>
        <attribute name="Timeformat" default="yyyy-MM-dd HH:mm:ss"/>
        <element name="Task" optional="yes"/>
        <sequential>
            <echo>生成jar文件</echo>
            <tstamp prefix="build.">
                <format property="timeSign" pattern="@{Timeformat}"/>
            </tstamp>
            <jar destfile="@{dest}" duplicate="@{duplicate}">
                <fileset dir="@{basedir}" includes="**/@{package}/*"/>
                <manifest>
                    <attribute name="Build-BY" value="@{buildBy}"/>
                    <attribute name="Build-time" value="${build.timeSign}"/>
                </manifest>

</jar>
            <Task/>
        </sequential>
    </macrodef>

<macrodef name="copyFile">
        <attribute name="to.dir" default="${build.src.dir}"/>
        <attribute name="to.test.src.dir" default="${build.test.src.dir}"/>
        <attribute name="from.dir" default="${src.dir}"/>
        <attribute name="from.test.src.dir" default="${test.src.dir}"/>
        <attribute name="includeFiles" default="**/*.*"/>

<element name="Task" optional="yes"/>
        <sequential>
            <echo>拷贝src文件</echo>
            <copy todir="@{to.dir}">
                <fileset dir="@{from.dir}" includes="@{includeFiles}"/>
            </copy>
            <copy todir="@{to.test.src.dir}">
                <fileset dir="@{from.test.src.dir}" includes="@{includeFiles}"/>
            </copy>
            <Task/>
        </sequential>
    </macrodef>

<macrodef name="zipFile">
        <attribute name="duplicate" default="preserve"/>
        <attribute name="dest" default="${build.zip.dir}/${project.zip.name}"/>

<!--要压缩的来源jar文件-->
        <attribute name="includeJar" default="${build.jar.dir}/*"/>
        <!--压缩文件里的目录前缀-->
        <attribute name="prefixjar" default="${project.prefix}/jar"/>

<attribute name="includesrcdir" default="${build.src.dir}"/>
        <!--要包含的文件-->
        <attribute name="includesrc" default="**/*.*"/>
        <attribute name="prefixsrc" default="${project.prefix}/src"/>

<attribute name="includedocdir" default="${build.doc.dir}"/>
        <!--要包含的文件-->
        <attribute name="includedoc" default="**/*.*"/>
        <attribute name="prefixdoc" default="${project.prefix}/doc"/>

<attribute name="includetestdir" default="${build.test.dir}"/>
        <!--要排除的文件-->
        <attribute name="excludes" default="report/"/>

<attribute name="prefixtest" default="${project.prefix}/test"/>

<element name="Task" optional="yes"/>
        <sequential>
            <echo>压缩zip文件</echo>
            <zip destfile="@{dest}" duplicate="@{duplicate}">
                <zipfileset file="@{includeJar}" prefix="@{prefixjar}"/>
                <zipfileset dir="@{includesrcdir}" includes="@{includesrc}" prefix="@{prefixsrc}"/>
                <zipfileset dir="@{includedocdir}" includes="@{includedoc}" prefix="@{prefixdoc}"/>
                <zipfileset dir="@{includetestdir}" includes="**/" excludes="@{excludes}" prefix="@{prefixtest}"/>
            </zip>
            <Task/>
        </sequential>
    </macrodef>

<macrodef name="warFile">
        <attribute name="type" default="war" />
        <attribute name="destfile" default="${build.jar.dir}/${web.name}.war" />
        <attribute name="filefrom" default="${web.dir}" />
        <attribute name="include" default="**/*" />
        <element name="Task" optional="yes"/>
        <sequential>
            <echo>生成war包</echo>
            <war destfile="@{destfile}">
                <fileset dir="@{filefrom}" includes="@{include}"/>
            </war>
            <Task/>
        </sequential>
    </macrodef>

<macrodef name="deployWar">
        <attribute name="todir" default="${env.CATALINA_BASE}/webapps" />
        <attribute name="warfrom" default="${build.jar.dir}/${web.name}.war" />
        <element name="Task" optional="yes"/>
        <sequential>
            <echo>部署war包</echo>
            <copy  todir="@{todir}" file="@{warfrom}" />
            <Task/>
        </sequential>
    </macrodef>

<macrodef name="createdatabase">
        <attribute name="userid" default="${root.username}" />
        <attribute name="password" default="${root.password}" />
        <attribute name="driver" default="${databaseDriver}" />
        <attribute name="classpath" default="compile-test-path" />
        <attribute name="url" default="${mysql.url}" />
        <attribute name="transaction.src" default="${sql.dir}/create.sql" />
        <element name="Task" optional="yes"/>
        <sequential>
            <echo>创建测试数据库</echo>
                <sql classpathref="@{classpath}" driver="@{driver}" userid="@{userid}" password="@{password}" url="@{url}">
                        <transaction src="@{transaction.src}" />
                </sql>
            <Task/>
        </sequential>
    </macrodef>
</project>

属性文件 build.properties

ftp.username=zl
ftp.password=123456
ftp.server=localhost
ftp.dir=user_manager
project.version=SNAPSHOT_0.1
project.name=usermanager
project.prefix=${project.name}_${project.version}
project.jar.name=${project.prefix}.jar
project.zip.name=${project.prefix}.zip
module.version=SNAPSHOT_0.1
dao.jar.name=user-dao-${module.version}.jar
service.jar.name=user-service-${module.version}.jar
controller.jar.name=user-controller-${module.version}.jar
model.jar.name=user-model-${module.version}.jar
captcha.jar.name=user-captcha-${module.version}.jar
web.name=user
databaseDriver=com.mysql.jdbc.Driver
root.username=root
root.password=root
username=ant_test
password=ant123
mysql.url=jdbc:mysql://localhost:3306/

使用文件build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <import file="basic.xml" />

<target name="clean">
        <cleanProject />
    </target>

<target name="initDir" depends="clean">
        <initDir>
            <inittask>
                <!--编译的次数和时间-->
                <buildnumber/>
                <propertyfile file="${metadata}/build.properties">
                    <entry key="Build-time" type="date" value="now" pattern="yyyy-MM-dd HH:mm:ss" />
                    <entry key="Build-number" type="int" value="${build.number}" />
                </propertyfile>

</inittask>
        </initDir>
    </target>

<target name="compile" depends="initDir">
        <compileSrcFile>
            <compiletask>
                <echo>拷贝配置文件</echo>
                <copy todir="${build.src.classes.dir}">
                    <fileset dir="${src.dir}" includes="**/*.xml,**/*.properties" />
                </copy>
            </compiletask>
        </compileSrcFile>
    </target>

<target name="compile-test" depends="compile">
        <compileTestSrcFile />
    </target>

<target name="createDatabase" depends="compile-test">
        <createdatabase/>
    </target>

<target name="run-test" depends="createDatabase">
        <runTest />
    </target>

<target name="docs" depends="run-test">
        <docFiles/>
    </target>

<target name="jarFiles" depends="docs">
        <jarFile dest="${build.jar.dir}/${model.jar.name}"  package="model"/>
        <jarFile dest="${build.jar.dir}/${dao.jar.name}"  package="dao"/>
        <jarFile dest="${build.jar.dir}/${service.jar.name}"  package="service"/>
        <jarFile dest="${build.jar.dir}/${captcha.jar.name}"  package="captcha"/>

</target>

<target name="copyFiles" depends="jarFiles">
        <copyFile/>
    </target>

<target name="war" depends="copyFiles">
        <warFile/>
    </target>
    <target name="zipFiles" depends="war">
        <zipFile/>
    </target>

<target name="DeployWar" depends="zipFiles">

<deployWar/>
    </target>

<target name="end" depends="DeployWar">
        <echo>整个过程结束</echo>
    </target>

</project>

使用ant宏定义任务的更多相关文章

  1. c++宏定义命令

    在程序开始以#开头的命令,他们是预编译命令.有三类预编译命令:宏定义命令.文件包含命令.条件编译命令:今天聊聊宏定义: 宏定义命令将一个标识符定义为一个字符串,源程序中的该标识符均以指定的字符串来代替 ...

  2. dll导入导出宏定义,出现“不允许 dllimport 函数 的定义”的问题分析

    建立dll项目后,在头文件中,定义API宏 #ifndef API_S_H #define API_S_H ...... #ifndef DLL_S_20160424 #define API _dec ...

  3. iOS之常用宏定义

    下面我为大家提供一些常用的宏定义! 将这些宏定义 加入到.pch使用 再也不用 用一次写一次这么长的程序了 //-------------------获取设备大小------------------- ...

  4. linux中offsetof与container_of宏定义

    linux内核中offsetof与container_of的宏定义 #define offsetof(TYPE, MEMBER)    ((size_t) &((TYPE *)0)->M ...

  5. Linux Kernel代码艺术——系统调用宏定义

    我们习惯在SI(Source Insight)中阅读Linux内核,SI会建立符号表数据库,能非常方便地跳转到变量.宏.函数等的定义处.但在处理系统调用的函数时,却会遇到一些麻烦:我们知道系统调用函数 ...

  6. 面试问题5:const 与 define 宏定义之间的区别

    问题描述:const 与 define 宏定义之间的区别 (1) 编译器处理方式不同     define宏是在预处理阶段展开:     const常量是编译运行阶段使用: (2) 类型和安全检查不同 ...

  7. 关于Xcode8.1 / iOS10+ 真机测试系统打印或者宏定义打印不显示问题

    前言: 最近做项目时遇到了很多莫名其妙的问题,其中就有这个打印(NSLog).也不多废话了,我们先来回顾一下Xcode8发布以来,我们遇到的一些关于打印的问题,当然也有解决方法: 1.Xcode8打印 ...

  8. JDStatusBarNotification和一些宏定义

    // //  AddTopicViewController.m //  vMeet2 // //  Created by 张源海 on 16/6/30. //  Copyright © 2016年 h ...

  9. #define宏定义形式的"函数"导致的bug

    定义了一个宏定义形式的"函数": #define  SUM8(YY)\ {\ int Y = YY>>2;\ ...\ } 然后使用的时候,传入了一个同名的变量Y: i ...

随机推荐

  1. 【小梅哥SOPC学习笔记】系统时钟的使用

    给NIOS II CPU添加一颗澎湃的心——系统时钟的使用 本实验介绍如何在Qsys中添加一个定时器作为NIOS II的心跳定时器,并在NIOS II中软件编程使用该定时器. 将上一个实验watchd ...

  2. 哇,两门学考都是A(〃'▽'〃)

    看来只要拼命去搞,两个月也是可以搞出来的啊~

  3. 学习做爬虫-vs2017

    最近新装了vs2017,安装过程发生了很大的变化,操作变的更加容易了. 下载vs安装程序进行安装.更新界面如图所示,我选择了安装免费个人版(这个是已安装的更新界面,和安装界面差不多) 如图所示,这样的 ...

  4. CentOS下Docker与.netcore(五)之 三剑客之一Docker-swarm集群

    CentOS下Docker与.netcore(一) 之 安装 CentOS下Docker与.netcore(二) 之 Dockerfile CentOS下Docker与.netcore(三)之 三剑客 ...

  5. IIS7 配置ssl证书 多域名绑定443端口

    IIS7下多个子域名同时配置https协议,但IIS7默认支持单个443端口造成端口冲突: 解决方案:先把每个域名配置不同的端口 例:444,445,446等 然后在:C:\Windows\syste ...

  6. Mysql内置功能《三》视图

    一 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...

  7. react学习之路-配制antd-mobile

    经过将近三个月的使用,现在终于在我老大的带领下做完了一个react的项目,感觉还可以,最大的不足就是,对于react中的很多的东西都是掺杂着jq使用来做的,这是最不满意的一点吧,但是开发进度很近,只能 ...

  8. hdu3698 Let the light guide us(dp+线段树)

    题意:在每行上选一个点,每个点都要各自对应的代价,同时相邻两行的点要满足 |j-k|≤f(i,j)+f(i+1,k).问最小代价是多少. 题解: 不难发现这是一道dp,状态转移方程如下$dp[i][j ...

  9. SP16549 QTREE6 - Query on a tree VI(LCT)

    题意翻译 题目描述 给你一棵n个点的树,编号1~n.每个点可以是黑色,可以是白色.初始时所有点都是黑色.下面有两种操作请你操作给我们看: 0 u:询问有多少个节点v满足路径u到v上所有节点(包括)都拥 ...

  10. [AIR] AIR将数据保存并导出为Excel

    package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.filesystem.File; ...