浏览 3734 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-04-16
1. basename Sets a property to the last element of a specified path in an effort to determine a file's name without directory structure 2. dirname Assigns a file's directory path to a property 3. input Displays a message and reads a line of input from the console, allowing for user input during the build process 4. import Allows the use of other Ant files 5. record Runs a listener that records the logging output of the build process to a file 6. sequential A container task that can contain other Ant tasks and run them in sequence 7. rmic Invokes the rmic compiler 8. subant Runs Ant within all subdirectories of the project directory 9. tstamp Sets time-based properties to the current time 10. Ant has some additional Ant-specific properties: ant.file Contains the absolute path of the build file ant.java.version Contains the JVM version Ant is using (can hold only 1.1, 1.2, 1.3, 1.4 and [as of Ant 1.6] 1.5) ant.project.name Holds the name of the project that is executing (set with the name attribute of project) ant.version Contains the version of Ant running basedir Holds the absolute path of the project's base directory (set with the basedir attribute of project) ======================= 摘抄自 java development with ant ant-contrlib的一些task,觉得可能有用的 1. propertycopy,感觉有点像赋值,但是不是简单的赋值 <target name="propertycopy"> <property name="X" value="Y"/> <property name="Y" value="Z"/> <propertycopy name="A" from="${X}"/> <echo message="A = ${A}"/> </target> The value of ${X} is “Y”. The from attribute of <propertycopy> refers to an Ant property name, “Y” in this example. The value of the property Y is “Z”, so the output is “A = Z”. This is a much nicer alternative than using the refid tricks. 2.osfamily 和操作系统相关的 <target name="osfamily"> <osfamily property="os.family" /> <echo message="O/S family is ${os.family}"/> <property file="${os.family}.properties"/> </target> Executing this target on a Windows 2000 machine would load windows.properties. Loading properties based on operating system family, or by hostname, enables build files to adapt easily to their operating environment. 3. Using if/then/else logic 逻辑判断,觉得会用到 <target name="if"> <if> <equals arg1="${foo}" arg2="bar" /> <then> <echo message="The value of property foo is bar" /> </then> <else> <echo message="The value of property foo is not bar" /> </else> </if> </target> 4. Multiple value switching 开关控制 <target name="switch"> <switch value="${foo}"> <case value="bar"> <echo message="The value of property foo is bar" /> </case> <case value="baz"> <echo message="The value of property foo is baz" /> </case> <default> <echo message="The value of property foo is not sensible" /> </default> </switch> </target> 5. Catching task exceptions 使用try catch,不知道用处有多大 <target name="trycatch"> <trycatch property="exception.message" reference="exception.ref"> <try> <fail>Oops!</fail> </try> <catch> <echo>Caught</echo> </catch> <finally> <echo>Finally</echo> </finally> </trycatch> <echo>As property: ${exception.message}</echo> <property name="exception.value" refid="exception.ref" /> <echo>From reference: ${exception.value}</echo> </target> ..... Executing this target produces this output: trycatch: [trycatch] Caught exception: Oops! [echo] Caught [echo] Finally [echo] As property: Oops! [echo] From reference: C:\AntBook\Sections\Applying\tasks\ ant-contrib.xml:72: Oops! BUILD SUCCESSFUL 6. Using explicit iteration ,我一般使用for, 不知道为什么,这个应该还有点用处的吧 <target name="for-each"> <foreach list="1,2,3" target="loop" param="var" delimiter=","> <fileset dir="."/> </foreach> </target> <target name="loop"> <echo message="var = ${var}"/> </target> ... out put is for-each: loop: [echo] var = 1 loop: [echo] var = 2 loop: [echo] var = 3 loop: [echo] var = C:\AntBook\Sections\Applying\tasks\ant-contrib.xml loop: [echo] var = C:\AntBook\Sections\Applying\tasks\build\build.properties . . The target is invoked for each iteration by using the underlying mechanism that the <antcall> task uses, which means that the dependencies of the target are reevaluated each iteration. 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-04-16
偶不知如果ANT不和其它的东西结合,
它的作用还有多大. 反正偶是常用ANT的. jar javac javadoc war 还有就是和XDOCLET结合了吧, 生struts spring等配置文件呗. COPY当然也用. 但是肯定是和别的一起. |
|
返回顶楼 | |
发表时间:2008-04-16
嗯, 那肯定是要和其他内容结合,他本就是个配置的东东啊,
前些日子需要在 ant中有判断,能获得某个目录下的文件,然后调用每个文件,虽然可以另写个task,但如果已经有现成的为什么不用呢, 另外,如果能获得某个文件(夹)的名字,而不是全路径,basename给了很大的帮助,呵呵 |
|
返回顶楼 | |