当前位置: 首页 > news >正文

ant 学习(4)--常用task

 ant核心task


antInvokes Ant on another buildfile.
antcallCalls a target in the current buildfile.
antstructureCreates an XML Document Type Definition (DTD) for Ant buildfiles.
applyExecutes a system command on a set of files.
availableSets a property if a resource is available.
chmodChanges permissions on files and directories (Unix platforms only).
conditionSets a property if a condition is true.
copyCopies files and directories.
copydirDeprecated in Ant 1.2; use the copy task instead.
copyfileDeprecated in Ant 1.2; use the copy task instead.
cvsExecutes Concurrent Versions System (CVS) commands.
cvspassAdds passwords to a .cvspass file; equivalent to the CVS login command.
deleteDeletes files and directories.
deltreeDeprecated in Ant 1.2; use the delete task instead.
dependsetManages dependencies between files, removing|target files if any are out-ofdate
earBuilds Enterprise Application Archive (EAR) files.
echoWrites a message to the Ant log or a file.
execExecutes a native system command.
execonDeprecated in Ant ; use the apply task instead.
failThrows a BuildException, causing the current build to terminate.
filterSets token filters for the current project.
fixcrlfCleans up special characters in source files, such as tabs, carriage returns,linefeeds, and EOF characters.
genkeyGenerates a key in a keystore.
getGets a file from a URL.
gunzipUnzips a GZip file.
gzipCreates a GZip file.
jarCreates a JAR file.
javaExecutes a Java class.
javacCompiles Java source code.
javadocRuns the JavaDoc utility to generate source code documentation.
mailSends email using SMTP.
mkdirCreates a directory.
moveMoves files and directories.
parelExecutes multiple tasks in concurrent threads.
patchApplies a diff file to originals.
pathconvertConverts Ant paths into platform-specific paths.
propertySets properties in the project.
recordLogs output from the current build process.
renameDeprecated in Ant 1.2; use the move task instead.
replacePerforms string replacement in one or more files.
rmicRuns the rmic compiler.
sequentialExecutes multiple tasks sequentiy; designed for use with the parel task.
signjarExecutes the javasign command-line tool.
sleepPauses the build for a specified interval.
sqlExecutes SQL commands using JDBC.
stylePerforms XSLT transformations.
tarCreates a tar archive.
taskdefAdds custom tasks to the current project.
touchUpdates the timestamp of one or more files.
tstampSets the DSTAMP, TSTAMP, and TODAY properties.
typedefAdds a DataType to the current project.
unjarExpands a ZIP file, WAR file, or JAR file.
untarExpands a tar file.
unwarExpands a ZIP file, WAR file, or JAR file.
unzipExpands a ZIP file, WAR file, or JAR file.
uptodateSets a property if one or more target files are up-to-date with respect to corresponding source files
warCreates a Web Application Archive (WAR) file.
zipCreates a ZIP file.

 


ant

Invoke the default target on util_buildfile.xml in the current directory:
<ant antfile="util_buildfile.xml"/>
Invoke the clean target on build.xml in the gui directory:
<ant dir="gui" target="clean"/>
Invoke  another buildfile, passing a new value for the builddir property. The  value is explicitly set to utiloutput even if the property was defined  elsewhere in the calling buildfile:
<ant antfile="util_buildfile.xml">
<property name="builddir" value="utiloutput"/>
</ant>

 

Copy

This example copies all Java source files to a new directory, replacing all occurrences of@VERSION@ with the value of app.version.
<copy todir="${builddir}/srccopy">
<fileset dir="${srcdir}">
<include name="**/*.java"/>
</fileset>
<filterset>
<filter token="VERSION" value="${app.version}"/>
</filterset>
</copy>

 

delete

Here is a common target found in just about every Ant buildfile. It deletes the build directory and all of its contents:
<target name="clean" description="Remove all generated code">
<delete dir="${builddir}"/>
</target>

 

echo

The  first of the following examples specifies the text to write using the  message attribute. The second example specifies the text to write by  enclosing it within <echo>...</echo> tags.
<echo message="Building to ${builddir}"/>
<echo>You are using version ${java.version}
of Java! This message spans two lines.</echo>

 

javac

Compile all Java source files in the com.oreilly.antbook package and subpackages, placing results in ${builddir}:
<javac srcdir="${srcdir}"
destdir="${builddir}"
includes="com/oreilly/antbook/**"/>

 

mkdir

This  task is commonly used in a prepare target that other targets depend on.  This ensures that necessary destination directories are created before  other targets are executed.

<target name="prepare">
<mkdir dir="${builddir}"/>
<mkdir dir="${deploydir}/docs"/>
</target>
<target name="compile" depends="prepare">
...
</target>

 

sleep

<!-- start a web server, then wait a few seconds for it to initialize -->
<sleep seconds="10"/>
<!-- now start the client unit tests -->


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<? xml  version = "1.0"
encoding = "GBK" ?>
[code] <!-- 定义生成文件的project根元素,默认的target为空
-->
< project  name = "antQs"  basedir = "."
default = "" >
<!-- 定义三个简单属性 -->
< property  name = "src"
value = "src" />
< property  name = "classes"
value = "classes" />
< property  name = "dest"
value = "dest" />
<!-- 定义一组文件和目录集 -->
< path  id = "classpath" >
      < pathelement
path = "${classes}" />
</ path >
<!-- 定义help target,用于输出该生成文件的帮助信息
-->
< target  name = "help"
description = "打印帮助信息" >
      < echo >help -
打印帮助信息</ echo >
      < echo >compile
- 编译Java源文件</ echo >
      < echo >run -
运行程序</ echo >
      < echo >build
- 打包JAR包</ echo >
      < echo >clean
- 清除所有编译生成的文件</ echo >
</ target >
<!-- 定义compile target,用于编译Java源文件
-->
< target  name = "compile"
description = "编译Java源文件" >
      <!-- 先删除classes属性所代表的文件夹
-->
      < delete
dir = "${classes}" />
      <!-- 创建classes属性所代表的文件夹
-->
      < mkdir
dir = "${classes}" />
      <!--
编译Java文件,编译后的class文件放到classes属性所代表的文件夹内 -->
      < javac  destdir = "${classes}"
debug = "true"
            deprecation = "false"
optimize = "false"  fail>
            <!--
指定需要编译的Java文件所在的位置 -->
            < src
path = "${src}" />
            <!--
指定编译Java文件所需要第三方类库所在的位置 -->
            < classpath
refid = "classpath" />
      </ javac >
</ target >
<!-- 定义run target,用于运行Java源文件,
      运行该target之前会先运行compile target
-->
< target  name = "run"  description = "运行程序"
depends = "compile" >
      <!--
运行lee.HelloTest类,其中fork指定启动另一个JVM来执行java命令 -->
      < java
classname = "lee.HelloTest"  fork = "yes"  fail>
            < classpath
refid = "classpath" />
            <!--
运行Java程序时传入2个参数 -->
            < arg
line = "测试参数1 测试参数2" />
      </ java >
</ target >
<!-- 定义build target,用于打包JAR文件,
      运行该target之前会先运行compile target
-->
< target  name = "build"  description = "打包JAR文件"
depends = "compile" >
      <!-- 先删除dest属性所代表的文件夹
-->
      < delete
dir = "${dest}" />
      <!-- 创建dest属性所代表的文件夹
-->
      < mkdir
dir = "${dest}" />
      <!--
指定将classes属性所代表的文件夹下的所有
            *.classes文件都打包到app.jar文件中
-->
      < jar
destfile = "${dest}/app.jar"  basedir = "${classes}"
            includes = "**/*.class" >
            <!--
为JAR包的清单文件添加属性 -->
            < manifest >
                < attribute
name = "Main-Class"  value = "lee.HelloTest" />
            </ manifest >
      </ jar >
</ target >
<!-- 定义clean target,用于删除所有编译生成的文件
-->
< target  name = "clean"
description = "清除所有编译生成的文件" >
      <!-- 删除两个目录,目录下的文件也一并删除
-->
      < delete
dir = "${classes}" />
      < delete
dir = "${dest}" />
</ target >
</ project >



本文转自 326647452 51CTO博客,原文链接:http://blog.51cto.com/svsky/2074018,如需转载请自行联系原作者

相关文章:

  • 33.Apollo引入第三方Jar包编译
  • IT团队需要的10个关键安全能力
  • 如何禁用MacOS High Sierra中的「重要地点」位置跟踪
  • 有些话只说与懂得的人听
  • 进化者机器人完成 8 千万元 A+ 轮融资,还推出了教师助手小胖
  • 解决高版本Chrome浏览器扩展程序强制停用问题
  • 修改Active Directory域控制器IP地址
  • 高速串行接口数据流向
  • 《我也能做CTO之.程序员职业规划》 水准之上,期望以下
  • Vue.js系列之二Vue实例
  • 技术:超级实用的电脑小技巧
  • Linux gpio口使用方法
  • 枚举和注解结合使用威力更大
  • 七个人生工具:SWOT、PDCA、6W2H、SMART、WBS、时间管理、二八原则
  • 剑指offer(一) 二维数组的查找
  • 08.Android之View事件问题
  • 5分钟即可掌握的前端高效利器:JavaScript 策略模式
  • Java的Interrupt与线程中断
  • js如何打印object对象
  • JS数组方法汇总
  • Spring Cloud中负载均衡器概览
  • 极限编程 (Extreme Programming) - 发布计划 (Release Planning)
  • 简单数学运算程序(不定期更新)
  • 前嗅ForeSpider采集配置界面介绍
  • 网络应用优化——时延与带宽
  • 微信如何实现自动跳转到用其他浏览器打开指定页面下载APP
  • 限制Java线程池运行线程以及等待线程数量的策略
  • 用jQuery怎么做到前后端分离
  • 原生Ajax
  • Android开发者必备:推荐一款助力开发的开源APP
  • 曾刷新两项世界纪录,腾讯优图人脸检测算法 DSFD 正式开源 ...
  • ​水经微图Web1.5.0版即将上线
  • #if和#ifdef区别
  • $refs 、$nextTic、动态组件、name的使用
  • (16)Reactor的测试——响应式Spring的道法术器
  • (32位汇编 五)mov/add/sub/and/or/xor/not
  • (4)logging(日志模块)
  • (ibm)Java 语言的 XPath API
  • (笔试题)分解质因式
  • (超详细)语音信号处理之特征提取
  • (二)linux使用docker容器运行mysql
  • (九)c52学习之旅-定时器
  • (九十四)函数和二维数组
  • (七)c52学习之旅-中断
  • (转)VC++中ondraw在什么时候调用的
  • *p=a是把a的值赋给p,p=a是把a的地址赋给p。
  • .net FrameWork简介,数组,枚举
  • .Net FrameWork总结
  • .NET MAUI学习笔记——2.构建第一个程序_初级篇
  • .NET/C# 编译期能确定的字符串会在字符串暂存池中不会被 GC 垃圾回收掉
  • .NET/C# 使用反射调用含 ref 或 out 参数的方法
  • .Net8 Blazor 尝鲜
  • .net实现客户区延伸至至非客户区
  • .NET正则基础之——正则委托
  • .vue文件怎么使用_vue调试工具vue-devtools的安装