关键词不能为空

当前您在: 主页 > 英语 >

ant使用教程

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-28 05:53
tags:

-

2021年2月28日发(作者:乙炔雌二醇)


Ant


是什么?



A nt


是一种基于


Java


< p>
XML



build


工具 。




2


下载、安装


Ant


安装


Ant


下载

.zip


文件,解压缩到


c:ant1.3(


后面引用为


%ANT_HOME%)



2.1


在你运行


Ant


之前需要做一些配置工作。



?

< br>将


bin


目录加入


PATH


环境变量。



?


设定


ANT_HOME


环境变量,指向你安装


Ant


的目录。在一些


OS


上 ,


Ant


的脚本可以猜测


ANT_HO ME



Unix


Windos NT/2000


)-但最好不要依赖这一特性。



?


可选地,设定


JAVA_HOME


环境变量(参考下面的高级小节)


,该变量应该指向你安装


JDK


的目录。



注意:不要将


Ant




文件放到


JDK/JRE



l ib/ext


目录下。


Ant


是个应用 程序,而


lib/ext


目录是为


JD K


扩展使用的(如


JCE


< p>
JSSE


扩展)


。而且通过扩展装入的类会有安全 方


面的限制。



2.2


运行


Ant


运行


Ant


非常简单,当你正确地安装

Ant


后,只要输入


ant


就可以 了。




n


没有指定任何参数时,


Ant


会在当前目录下查询



文件。如果找到了就用该文件


作为

< br>buildfile


。如果你用


-find


选项。


Ant


就会在上级目录中寻找

< p>
buildfile


,直至到达


文件系统的根。< /p>


要想让


Ant


使用其他的


buildfile



可以用参数

-buildfile


file


这里


file


指定了你想使用的


b uildfile





n


可以指定执行一个或多个


targ et


。当省略


target


时,


Ant


使用标签




default


属性所指定的


target






命令行选项总结:



ant [options] [target [target2 [target3] ...]]


Options:


-help print this message


-projecthelp print project help information


-version print the version information and exit


-quiet be extra quiet


-verbose be extra verbose


-debug print debugging information


-emacs produce logging information without adornments


-logfile file use given file for log output


-logger classname the class that is to perform logging


-listener classname add an instance of class as a project listener


-buildfile file use specified buildfile


-find


file


search


for


buildfile


towards


the


root


of


the


filesystem


and


use


the


first


one found


-Dproperty=value set property to value


例子



ant


使用当前目录下的



运行


Ant


,执行缺省的


target




ant -buildfile


使用当前目录下 的



运行


Ant


,执行缺省的


target




ant -buildfile dist


使用当前目录下 的



运行


Ant


,执行一个叫做


dist



targe t




ant -buildfile -Dbuild=build/classes dist


使用当前目录下的



运行


Ant


,执行一个 叫做


dist



target


,并设定


build


属性的

值为


build/classes





3


编写




A nt



buildfile


是用


XML


写的。每个


buildfile


含有一个


project


< br>



buildfile


中每个


task


元素可以有一个


id


属性,


可以用这个


id


值引用指定的任务。


这个值


必须是唯一的。

(详情请参考下面的


Task


小节)




3.1 Projects



project


有下面的属性:



Attribute Description Required


name


项目名称


. No


default


当没有指定


targ et


时使用的缺省


target Yes


basedir


用于计算所有其他路径的基路径。

< p>
该属性可以被


basedir


property


覆盖。


当覆盖时,


该属性被忽略。


如果属性和


basedir


proper ty


都没有设定,


就使用


buildf ile


文件的父目录。



No


项目的描述以一个顶级的



元素的形式出现(参看


description


小节)





一个项 目可以定义一个或多个


target


。一个

target


是一系列你想要执行的。执行


Ant


时,


你可以选择执行那个


target


。当没有给定


target


时,使用

< p>
project



default


属性所确定



target





3.2 Targets



一个


target

< br>可以依赖于其他的


target


。例如,你可能会有一个


target


用于编译程序,一个


ta rget


用于生成可执行文件。


你在生成可执行文件之前必须先 编译通过,


所以生成可执行文


件的


ta rget


依赖于编译


target


。< /p>


Ant


会处理这种依赖关系。




然而,


应当注意到,


Ant



depends


属性 只指定了


target


应该被执行的顺序-如果被依赖的


target


无法运行,这种


depends


对于指定了依赖关系的


target


就 没有影响。




Ant


会依照


depends


属性中


target


出现的顺序


(从左到右)


依次执行每个


target



然而,< /p>



记住的是只要某个


target


依赖于一个


target


,后者就会被先执行 。







假定我们要执行


target D

< br>。从它的依赖属性来看,你可能认为先执行


C


,然后


B


,最后


A



执行。错了,


C


依赖于

B



B


依赖于

A


,所以先执行


A


,然后


B


,然后


C


,最后


D


被执行。



< /p>


一个


target


只能被执行一次,即时 有多个


target


依赖于它(看上面的例子)





如果(或如果不)某些 属性被设定,才执行某个


target


。这样,允许根据系统的 状态(


java


version, OS,


命令行属性定义等等)来更好地控制


build


的过程 。要想让一个


target


这样


做,你 就应该在


target


元素中,加入


i f


(或


unless


)属性,带上


target


因该有所判断的属


性。例如:





如果没有


if



unless


属性,


target


总会被执行。




可选的


description


属性可用来提供关于


target


的一行描 述,这些描述可由


-projecthelp


命令行选项输出。




将你的


tstamp task


在一个 所谓的初始化


target


是很好的做法,其他的


target


依赖这个初


始化


target



要确保初始化


tar get


是出现在其他


target


依赖 表中的第一个


target



在本手< /p>


册中大多数的初始化


target


的名字 是






target


有下面的属性:



Attribute Description Required


name target


的名字


Yes


depends


用逗号分隔的


target


的名字列表,也就是依赖表。


No


if


执行


target


所需要设定的属性名。


No


unless


执行


target


需要清除设定的属性名。


No


description


关 于


target


功能的简短描述。


No



3.3 Tasks



一个


task


是一段可执行的代码。




一个


task< /p>


可以有多个属性(如果你愿意的话,可以将其称之为变量)


。属性 只可能包含对


property


的引用。这些引用会在


task


执行前被解析。




下面是


Task

的一般构造形式:




这里


name



task


的名字,


attributeN

是属性名,


valueN


是属性值。




有一套内置的(


built-i n



task


,以及一些可选


task


,但你也可以编写自己的


task





所有的


task


都有一个


task


名字属性。


Ant


用属性值来产生日志信息。




可以给


task< /p>


赋一个


id


属性:




这里


taskname



task


的名字, 而


taskID


是这个


task


的唯一标识符。通过这个标识符,你


可以在脚本中引用相应的


task


。例如,在脚本中你可以这样:




设定某个


task


实例的


foo

属性。在另一个


task


中(用


j ava


编写)


,你可以利用下面的语句


存取相应的实例。



erence(


注 意


1



如果


t ask1


还没有运行,


就不会被生效


( 例如:


不设定属性)



如果你在随后配 置它,


你所作的一切都会被覆盖。




注意


2


:未来的


Ant


版本可能不会兼容这里所提的属性,因为很有可能根本没有

task


实例,


只有


proxie s





3.4 Properties



一 个


project


可以有很多的


pro perties


。可以在


buildfile

< br>中用


property


task


来设定,或



Ant


之外设定。一个


property


有一个名字和一个值。


property


可用于


task


的 属性值。这


是通过将属性名放在





之间并放在属性值的位置来实现的。例如如果有一个


property


builddir


的值是




这个


propert y


就可用于属性值:


$${builddir}/classes



这个值就可被解析为


build/c lasses





内置属性




如果你使用了


task


定义了所有的系统属性,


Ant


允许你使用这些属性 。例如,


$${}


对应操作系统的名字。




要想得到系统属性的列表可参考


the Javadoc of perties





除了


Java


的系统属性,


A nt


还定义了一些自己的内置属性:



basedir project


基目录的绝对路径


(





basedi r


属性一样


)




buildfile


的绝对路径。



n Ant


的版本。



< br>当前执行的


project


的名字;由

< br>



name


属性设定


.


n


Ant


检测到的


JVM


的版本;



目前的值有




< /p>


and




例子





































3.5 Path-like Structures


你可以 用





作为分隔 符,


指定类似


PATH



CLASSPATH


的引用。


Ant


会把分隔符转换为


当前系统所用的分隔符。




当需要指定类似路径的值时,可以使用嵌套元素。一般的形式是







locati on


属性指定了相对于


project


基目录的一个文件和目录,而


path


属性接受逗号或分

-


-


-


-


-


-


-


-



本文更新与2021-02-28 05:53,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/679093.html

ant使用教程的相关文章