• Ant:build.xml 结构


    •  Ant build.xml 结构

    Ant build.xml 结构

     

    最基本的build.xml结构:

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

    <project name="test" default="main">

        <property name="test.prop1" value="hello, java"/>

        <target name="main">

           <echo>${test.prop1}</echo>

        </target>

    </project>

    根元素是projectproject下可以包括多个target,每个target下可以有多个task

    另外还可以指定task在执行过程中使用的数据,例如property

     

    build.xml的基本结构就是:projecttargettaskdatadef

    下面就针对这些元素分别说明:

     

    project

        每个ant的构建文件(build.xml)都必须以project元素做为根元素,

     

    属性

    描述

    必要

    name

    名称

    default

    指定默认的target

    basedir

    计算build.xml中路径的基路径。默认值是build.xml文件所在的目录。

     

     

    target

        一个target包括多个task,通过多个task来达成想要的目标。一个target可以依赖于其它的targets

       

    <target name="A"/>

    <target name="B" depends="A"/>

    <target name="C" depends="B"/>

    <target name="D" depends="C,B,A"/>

    假如要执行D目标,实际上的执行过程是这样的:

    Call-Graph:  A --> B --> C --> D

     

    Target的属性说明:

    Attribute

    Description

    Required

    name

    名称

    Yes

    depends

    指定依赖,用逗号分隔

    No

    if

    如果一个property name,那么这个property的值必须被设置。

    如果不是属性名,应该是一个可以被计算为true的表达式。

    No

    unless

    如果一个property name,那么这个property的值必须没有被设置。如果不是属性名,应该是一个可以被计算为false的表达式。

    No

    description

    描述

    No

    extensionOf

    Adds the current target to the depends list of the namedextension-pointsince Ant 1.8.0.

    No

    onMissingExtensionPoint

    What to do if this target tries to extend a missing extension-point. ("fail", "warn", "ignore"). since Ant 1.8.2.

    No. Not allowed unless extensionOf is present. Defaults to fail.

     

     

    示例:

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

    <project name="test" default="main">

        <property name="test.prop1" value="hello, ant"/>

        <target name="main" depends="IF_SET,IF_UNSET,UNLESS_SET,UNLESS_UNSET">

            <echo>${test.prop1}</echo>

        </target>

        <property name="test.a" value="hello, ant"/>

        <target name="IF_SET" if="test.a">

           <echo>IF_SET</echo>

        </target>

        <target name="IF_UNSET" if="test.b">

           <echo>IF_UNSET</echo>

        </target>

     

        <target name="UNLESS_SET" unless="test.a">

           <echo>UNLESS_SET</echo>

        </target>

        <target name="UNLESS_UNSET" unless="test.b">

           <echo>UNLESS_UNSET</echo>

        </target>

     

    </project>

     

    执行结果:

     

    IF_SET:

         [echo] IF_SET

     

    IF_UNSET:

     

    UNLESS_SET:

     

    UNLESS_UNSET:

         [echo] UNLESS_UNSET

     

    main:

         [echo] hello, ant

     

    BUILD SUCCESSFUL

    Total time: 0 seconds

     

     

    task

    task代表一个任务,target由一系统的task组成。

    每个task都有3个属性:

    Attribute

    Description

    Required

    id

    task实例的id,用于在其它地方引用这个任务时使用

    No

    taskname

    task实例的别名,在执行task时,如果指定了,日志中可以看到别名

    No

    description

    任务说明

    No

     

    示例:

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

    <project default="hello">

        <target name="hello">

           <echo taskname="echoMessage" id="echo_01">Hello, execute Ant task : [echo]</echo>

        </target>

    </project>

     

    结果:

     

    hello:

    [echoMessage] Hello, execute Ant task : [echo]

     

    BUILD SUCCESSFUL

    Total time: 0 seconds

     

    Ant内置了很多的task,可以在官方手册里找到:

    http://ant.apache.org/manual/,另外官方手册中,也对这些Ant任务进行了归类:


    data

        Anttask要执行,必不可少的是要使用数据。我将数据类型大致的分为几类:propertiespathfilesetselector、其他类型。

    这些数据内容,将在下一次说明。

      ·Property

      ·datatype

     

  • 相关阅读:
    反向代理实例
    nginx常用命令和配置
    nginx的安装
    Can Live View boot up images acquired from 64bit OS evidence?
    What is the behavior of lnk files?
    EnCase v7 search hits in compound files?
    How to search compound files
    iOS 8.3 JB ready
    Sunglasses
    现代福尔摩斯
  • 原文地址:https://www.cnblogs.com/f1194361820/p/5405179.html
Copyright © 2020-2023  润新知