ant 学习(4)--常用task

简介:

 ant核心task


ant Invokes Ant on another buildfile.
antcall Calls a target in the current buildfile.
antstructure Creates an XML Document Type Definition (DTD) for Ant buildfiles.
apply Executes a system command on a set of files.
available Sets a property if a resource is available.
chmod Changes permissions on files and directories (Unix platforms only).
condition Sets a property if a condition is true.
copy Copies files and directories.
copydir Deprecated in Ant 1.2; use the copy task instead.
copyfile Deprecated in Ant 1.2; use the copy task instead.
cvs Executes Concurrent Versions System (CVS) commands.
cvspass Adds passwords to a .cvspass file; equivalent to the CVS login command.
delete Deletes files and directories.
deltree Deprecated in Ant 1.2; use the delete task instead.
dependset Manages dependencies between files, removing|target files if any are out-ofdate
ear Builds Enterprise Application Archive (EAR) files.
echo Writes a message to the Ant log or a file.
exec Executes a native system command.
execon Deprecated in Ant ; use the apply task instead.
fail Throws a BuildException, causing the current build to terminate.
filter Sets token filters for the current project.
fixcrlf Cleans up special characters in source files, such as tabs, carriage returns,linefeeds, and EOF characters.
genkey Generates a key in a keystore.
get Gets a file from a URL.
gunzip Unzips a GZip file.
gzip Creates a GZip file.
jar Creates a JAR file.
java Executes a Java class.
javac Compiles Java source code.
javadoc Runs the JavaDoc utility to generate source code documentation.
mail Sends email using SMTP.
mkdir Creates a directory.
move Moves files and directories.
parel Executes multiple tasks in concurrent threads.
patch Applies a diff file to originals.
pathconvert Converts Ant paths into platform-specific paths.
property Sets properties in the project.
record Logs output from the current build process.
rename Deprecated in Ant 1.2; use the move task instead.
replace Performs string replacement in one or more files.
rmic Runs the rmic compiler.
sequential Executes multiple tasks sequentiy; designed for use with the parel task.
signjar Executes the javasign command-line tool.
sleep Pauses the build for a specified interval.
sql Executes SQL commands using JDBC.
style Performs XSLT transformations.
tar Creates a tar archive.
taskdef Adds custom tasks to the current project.
touch Updates the timestamp of one or more files.
tstamp Sets the DSTAMP, TSTAMP, and TODAY properties.
typedef Adds a DataType to the current project.
unjar Expands a ZIP file, WAR file, or JAR file.
untar Expands a tar file.
unwar Expands a ZIP file, WAR file, or JAR file.
unzip Expands a ZIP file, WAR file, or JAR file.
uptodate Sets a property if one or more target files are up-to-date with respect to corresponding source files
war Creates a Web Application Archive (WAR) file.
zip Creates 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,如需转载请自行联系原作者
相关文章
|
5月前
|
存储 Java 测试技术
Gradle笔记 四 Gradle的核心 TASK(二)
Gradle笔记 四 Gradle的核心 TASK
43 0
|
5月前
|
Java Maven
Gradle笔记 四 Gradle的核心 TASK(一)
Gradle笔记 四 Gradle的核心 TASK
46 0
|
9月前
hook+ant design实现input多行编写小案例
hook+ant design实现input多行编写小案例
31 0
jira项目笔记21-ant design table有tableProps属性
jira项目笔记21-ant design table有tableProps属性
96 0
jira学习案例17-hook+ts实现useArray小作业
jira学习案例17-hook+ts实现useArray小作业
46 0
jira学习案例17-hook+ts实现useArray小作业
|
前端开发
前端项目实战245-ant design radio设置默认值
前端项目实战245-ant design radio设置默认值
210 0
|
前端开发
#yyds干货盘点 【React工作记录十四】关于ant design中input加前缀的问题
#yyds干货盘点 【React工作记录十四】关于ant design中input加前缀的问题
109 0
#yyds干货盘点 【React工作记录十四】关于ant design中input加前缀的问题
|
前端开发
前端项目实战231-ant design table控制select可多选
前端项目实战231-ant design table控制select可多选
132 0
|
前端开发
前端项目实战190-ant design table设置默认分页
前端项目实战190-ant design table设置默认分页
147 0
|
前端开发
前端项目实战206-设置ant design table得前七行固定
前端项目实战206-设置ant design table得前七行固定
110 0