1.ant的安装

  1.1 添加环境变量:ANT_HOME=D:\software\ant\apache-ant-1.10.1

    在path中添加:%ANT_HOME%\bin

  1.2 测试是否安装成功

    在cmd中输入ant,如果出现如下提示表示安装成功

    

2.定义简单的build.xml

  2.1 创建HelloWord.java

package test;
public class HelloWorld{
public static void main(String[] args){
System.out.println("hello world!");
}
}

  2.2 创建build.xml

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

<!-- 定义project节点,和默认运行的target,和工作根目录 -->
<project name="HelloWorld" default="run" basedir="."> <!-- 定义变量 -->
<property name="src" value="src"/>
<property name="dest" value="classes"/>
<property name="hello_jar" value="hello.jar"/> <!-- 定义target -->
<target name="init">
<!-- 创建目录 -->
<mkdir dir="${dest}"/>
</target> <!-- depends:依赖的target -->
<target name="compile" depends="init">
<!-- 将srcdir目录中的文件进行编译,并将编译后的文件放入到destdir目录中 -->
<javac srcdir="${src}" destdir="${dest}"/>
</target> <target name="build" depends="compile">
<!-- 将basedir目录中的文件打成jar包 -->
<jar jarfile="${hello_jar}" basedir="${dest}"/>
</target> <target name="run" depends="build">
<!-- 运行classname -->
<java classname="test.HelloWorld" classpath="${hello_jar}"/>
</target> <target name="clean">
<!-- 删除dir目录和file文件 -->
<delete dir="${dest}"/>
<delete file="${hello_jar}"/>
</target> <target name="rerun" depends="clean,run">
<!-- 运行clean和run target -->
<ant target="clean"/>
<ant target="run"/>
</target>
</project>

3. 合并多个build.xml

  3.1 假设下边有三个小组,每个小组负责一部分,他们每个下面都有src和build.xml

  3.2 创建一个总的build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="main" default="build" basedir=".">
<property name="bin" value="${basedir}\bin"/>
<property name="src1" value="${basedir}\src1"/>
<property name="src2" value="${basedir}\src2"/>
<property name="src3" value="${basedir}\src3"/>
<target name="init">
<mkdir dir="${bin}"/>
</target>
<target name="run">
<!-- 分别运行各个目录下的target -->
<ant dir="${src1}" target="run"/>
<ant dir="${src2}" target="run"/>
<ant dir="${src3}" target="run"/>
</target>
<target name="clean">
<ant dir="${src1}" target="clean"/>
<ant dir="${src2}" target="clean"/>
<ant dir="${src3}" target="clean"/>
</target>
<target name="call">
<ant dir="${src1}" target="build"/>
<ant dir="${src2}" target="build"/>
<ant dir="${src3}" target="build"/>
</target>
<target name="build" depends="init,call">
<!-- 复制指定的文件到todir -->
<copy todir="${bin}">
<fileset dir="${src1}">
<include name="*.jar"/>
</fileset>
<fileset dir="${src2}">
<include name="*.jar"/>
</fileset>
<fileset dir="${src3}">
<include name="*.jar"/>
</fileset>
</copy>
</target>
<target name="rebuild" depends="build,clean">
<ant target="clean"/>
<ant target="build"/>
</target>
</project>

3 使用properties文件配置属性,和公共xml

  3.1 创建all.properties设置变量

src1=D:\\software\\ant\\test\\test3\\src1
src2=D:\\software\\ant\\test\\test3\\src2
src3=D:\\software\\ant\\test\\test3\\src3

  3.2 创建include.xml,设置公共的变量和target

<?xml version="1.0" encoding="UTF-8"?>
<property name="src" value="src"/>
<property name="dest" value="classes"/>
<target name="test">
<ant target="run"/>
</target>

  3.3 在总build中使用使用all.properties设置变量

<?xml version="1.0" encoding="UTF-8"?>
<project name="main" default="build" basedir=".">
<!-- 读取配置文件中的变量 -->
<property file="all.properties"/>
<property name="bin" value="${basedir}\bin"/>
<target name="init">
<mkdir dir="${bin}"/>
</target>
<target name="run">
<ant dir="${src1}" target="run"/>
<ant dir="${src2}" target="run"/>
<ant dir="${src3}" target="run"/>
</target>
<target name="clean">
<ant dir="${src1}" target="clean"/>
<ant dir="${src2}" target="clean"/>
<ant dir="${src3}" target="clean"/>
</target>
<target name="call">
<ant dir="${src1}" target="build"/>
<ant dir="${src2}" target="build"/>
<ant dir="${src3}" target="build"/>
</target>
<target name="build" depends="init,call">
<copy todir="${bin}">
<fileset dir="${src1}">
<include name="*.jar"/>
</fileset>
<fileset dir="${src2}">
<include name="*.jar"/>
</fileset>
<fileset dir="${src3}">
<include name="*.jar"/>
</fileset>
</copy>
</target> <target name="rebuild" depends="build,clean">
<ant target="clean"/>
<ant target="build"/>
</target> <target name="test">
<ant dir="${src1}" target="test"/>
<ant dir="${src2}" target="test"/>
<ant dir="${src3}" target="test"/>
</target>
</project>

  3.4 在每个小组的build.xml中引用include.xml的变量和target

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

<!-- 引入外部的xml,在本xml中就可以使用引入的xml中的变量和target -->
<!DOCTYPE project[
<!ENTITY share-variable SYSTEM "file:../include.xml">
]> <project name="HelloWorld" default="run" basedir=".">
<!-- 使用变量 -->
&share-variable; <!-- 这两个变量在公用的xml中已经定义,使用&share-variable就可直接使用
<property name="src" value="src"/>
<property name="dest" value="classes"/>
-->
<property name="hello_jar" value="hello1.jar"/>
<target name="init">
<mkdir dir="${dest}"/>
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${dest}"/>
</target>
<target name="build" depends="compile">
<jar jarfile="${hello_jar}" basedir="${dest}"/>
</target>
<target name="run" depends="build">
<java classname="test.HelloWorld" classpath="${hello_jar}"/>
</target>
<target name="clean">
<delete dir="${dest}"/>
<delete file="${hello_jar}"/>
</target>
<target name="rerun" depends="clean,run">
<ant target="clean"/>
<ant target="run"/>
</target>
</project>

ant的安装和使用的更多相关文章

  1. ANT的安装

    1.下载ANT http://ant.apache.org/bindownload.cgi 2.将下载下来的压缩包解压到任意文件夹下,例如D盘根目录下D:/apache-ant-1.9.2 3.添加环 ...

  2. tomcat, jdk, eclipse, ant的安装,设置及常见问题

    1.tomcat 安装: 安装版:在官方下载tomcat的安装版,根据提示一步步操作,很简单的 解压版:在官方下载tomcat的解压版,放到要安装的目录中解压版即可 同以前的找到设置环境变量的地方. ...

  3. Maven/Ant的安装(Win10 x64)

    一.Maven安装 1.官网下载安装包,http://maven.apache.org/download.cgi. 2.安装包解压到某一目录,然后配置maven的环境变量. PS:也可以不配置环境变量 ...

  4. Ant工具 ant的安装与配置 ant作用

    原文出自:http://blog.csdn.net/zhuche110/article/details/2663904点击打开链接 Ant是一种基于Java的build工具.理论上来说,它有些类似于( ...

  5. ant的安装及项目的发布

    1.安装ant1) 直接解压apache-ant-1.9.7-bin 2) 在环境变量中配置,ant_home的环境变量在 3) 在命令提示符中测试是否安装成功. 2 项目首次打包1) 写好打包的配置 ...

  6. ANT的安装和配置(windows)

    1.下载:到ANT官方网站http://ant.apache.org/下载最新版本,解压后即可.2.配置环境变量:我的电脑----属性-----高级----环境变量      如:ANT_HOME:C ...

  7. centos下ant的安装

    1.创建一个文件夹,用于安装ant.我们这里临时在/usr文件夹下创建ant文件夹. 2.下载 cd /usr/ant进入该文件夹,使用wget  ant的下载地址  下载ant到当前文件夹下.附an ...

  8. ubuntu中ANT的安装和配置

    一. 自动安装可以使用sudo apt-get install ant安装,但是这种装法不好.首先安装的ant不是最新的版本,其次还要装一堆其他的附带的东西.所以我才用自己手动ant安装. 二. 手动 ...

  9. Jmeter自动化集成工具Ant的安装

    一.Ant介绍 Apache Ant,是一个将软件编译.测试.部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发.由Apache软件基金会所提供.只要使用过Linux系统的读者 ...

随机推荐

  1. Redis项目实战,一些经验总结

    来源:https://my.oschina.net/u/920698/blog/3031587 背景 Redis 是一个开源的内存数据结构存储系统. 可以作为数据库.缓存和消息中间件使用. 支持多种类 ...

  2. CSS 清除浮动的几种方法

    导读: CSS 的 Float(浮动),会使元素向左或向右移动,其周围的元素也会重新排列,Float(浮动),往往是用于图像,使得文字围绕图片的效果,而它在布局时一样非常有用.不过有利也有弊,使用浮动 ...

  3. C#读取Xml中出现”&”等特殊符号

    原文:C#读取Xml中出现"&"等特殊符号 C#读取Xml中出现的特殊符号时用ASCII或者转定义名称代替.程序读进来后转成字符串后就自动变成相应的字符了,再度保存时会以正 ...

  4. saltstack基本操作第一篇章

    一.安装saltstack 1)官网安装 http://repo.saltstack.com/#rhel saltstack的模块:   https://www.unixhot.com/docs/sa ...

  5. Shell基本概述

    目录 Shell01--基本概述 1. Shell课程大纲介绍 2. 什么是Shell ? 3. 什么是Shell脚本 ? 4. 为什么要学Shell编程 ? 5. 学习Shell编程需要哪些知识 ? ...

  6. mysql基于Altas读写分离并实现高可用

    实验环境准备: master:192.168.200.111 slave1:192.168.200.112 slave2:192.168.200.113 Altas:192.168.200.114 c ...

  7. 西里尔字 俄语 - Cyrillic

    https://zh.wikipedia.org/wiki/%E8%A5%BF%E9%87%8C%E5%B0%94%E5%AD%97%E6%AF%8D 其他编码[编辑] 其他适用西里尔字母的字符编码系 ...

  8. 1.什么是微信小程序

    微信小程序,简称CX,是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或者搜一下即可打开应用.也体现了“用完即走”的理念,用户不用关心是否安装太多应用的问题. 应用将无处 ...

  9. 【多线程】LinkedTransferQueue

    LinkedTransferQueue是JDK1.7才添加的阻塞队列,基于链表实现的FIFO无界阻塞队列,是ConcurrentLinkedQueue(循环CAS+volatile 实现的wait-f ...

  10. PWM输出,呼吸灯

    一.初始化GPIO 使用PB1,查芯片手册对应TIM3_CH4 GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2 ...