使用ant宏定义任务
基础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宏定义任务的更多相关文章
- c++宏定义命令
在程序开始以#开头的命令,他们是预编译命令.有三类预编译命令:宏定义命令.文件包含命令.条件编译命令:今天聊聊宏定义: 宏定义命令将一个标识符定义为一个字符串,源程序中的该标识符均以指定的字符串来代替 ...
- dll导入导出宏定义,出现“不允许 dllimport 函数 的定义”的问题分析
建立dll项目后,在头文件中,定义API宏 #ifndef API_S_H #define API_S_H ...... #ifndef DLL_S_20160424 #define API _dec ...
- iOS之常用宏定义
下面我为大家提供一些常用的宏定义! 将这些宏定义 加入到.pch使用 再也不用 用一次写一次这么长的程序了 //-------------------获取设备大小------------------- ...
- linux中offsetof与container_of宏定义
linux内核中offsetof与container_of的宏定义 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->M ...
- Linux Kernel代码艺术——系统调用宏定义
我们习惯在SI(Source Insight)中阅读Linux内核,SI会建立符号表数据库,能非常方便地跳转到变量.宏.函数等的定义处.但在处理系统调用的函数时,却会遇到一些麻烦:我们知道系统调用函数 ...
- 面试问题5:const 与 define 宏定义之间的区别
问题描述:const 与 define 宏定义之间的区别 (1) 编译器处理方式不同 define宏是在预处理阶段展开: const常量是编译运行阶段使用: (2) 类型和安全检查不同 ...
- 关于Xcode8.1 / iOS10+ 真机测试系统打印或者宏定义打印不显示问题
前言: 最近做项目时遇到了很多莫名其妙的问题,其中就有这个打印(NSLog).也不多废话了,我们先来回顾一下Xcode8发布以来,我们遇到的一些关于打印的问题,当然也有解决方法: 1.Xcode8打印 ...
- JDStatusBarNotification和一些宏定义
// // AddTopicViewController.m // vMeet2 // // Created by 张源海 on 16/6/30. // Copyright © 2016年 h ...
- #define宏定义形式的"函数"导致的bug
定义了一个宏定义形式的"函数": #define SUM8(YY)\ {\ int Y = YY>>2;\ ...\ } 然后使用的时候,传入了一个同名的变量Y: i ...
随机推荐
- 基于 Web 的数据挖掘--自动抽取用 HTML、XML 和 Java 编写的信息
简介: 不可否认,万维网是到目前为止世界上最丰富和最密集的信息来源.但是,它的结构使它很难用系统的方法来利用信息.本文描述的方法和工具将使那些熟悉 Web 最常用技术的开发人员能快速而便捷地获取他们所 ...
- 8、Semantic-UI之其他按钮样式
8.1 其他按钮样式定义 示例:定义其他按钮样式 定义圆形图标按钮样式 <div class="ui circular icon button"><i class ...
- 二十、Node.js- WEB 服务器 (三)静态文件托管、 路 由
1.Nodejs 静态文件托管 上一讲的静态 web 服务器封装 项目结构: Web服务器封装成的模块:router.js代码: var http=require('http'); var fs=re ...
- Echart自定义y轴刻度信息2
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- java 线程 获取当前线程
java 线程 获取当前线程 Thread th=Thread.currentThread(); System.out.println("Tread name:"+th.getNa ...
- Angular 2 中的 ViewChild 和 ViewChildren
https://segmentfault.com/a/1190000008695459 ViewChild ViewChild 是属性装饰器,用来从模板视图中获取匹配的元素.视图查询在 ngAfter ...
- js 平均分割
let alllist=res.data; var result = []; for (var i = 0; i < alllist.length; i += 3) { result.push( ...
- JAVA 多线程 杂谈
一:java创建线程的三种方式: 1.继承Thread类: 2.实现Runnable接口: 3.实现Callable接口:Callable接口重写的是 call() 方法.1-允许有返回值,2-允许抛 ...
- 如何在NSDocumentDirectory内新建一个文件夹
iOS下载文件一般保存到NSDocumentDirectory内,但是为了更好整理文件内容,那就要自定义的生成一些文件夹,和做一些删除文件夹的操作. - (NSString *)pathToPatie ...
- python高级(二)—— python内置序列类型
本文主要内容 序列类型分类: (1)容器序列.扁平序列 (2)可变序列.不可变序列 列表推导式 生成器表达式 元组拆包 切片 排序(list.sort方法和sorted函数) bisect pytho ...