Iii. Key elements of build. xml:
1. project element
The project element is the root element of the ant component file. The ant component file should contain at least one project element,
Otherwise, an error occurs. Each project element can contain multiple target elements. Next, we will show you the attributes of the project element.
1) Name attribute
Specifies the name of the project element.
2) default attribute
Specifies the name of the target to be executed when the project is executed by default.
3) basedir attributes
Specifies the location of the base path. When this attribute is not specified, the attachment directory of the ant component file is used as the reference directory.
2. Target Element
Target is the basic execution unit of ant. It can contain one or more specific tasks. Multiple targets can be interdependent.
It has the following attributes:
1) Name attribute
Specifies the name of the target element. This attribute is unique in a project element.
You can specify a target by specifying the target element name.
2) depends attributes
Describe the dependency between targets. If there is a dependency with multiple targets,
It must be separated by commas. Ant executes each target in sequence according to the order in which the target appears in the depends attribute.
The target to be depended on will be executed first.
3) If attributes
Used to verify whether the specified property exists. If it does not exist, the target will not be executed.
4) Unless attributes
The function of this attribute is opposite to that of the IF property. It is also used to verify whether the specified property exists,
If the target does not exist, the target will be executed.
5) description attribute
This attribute is a brief description and description of the target function.
3. Property Element
The property element can be seen as a parameter or Parameter definition. The property of a project can be set through the property element,
You can also set it out of ant. To introduce an external file, such as the build. properties file,
You can introduce it as follows:
<Property file = "build. properties"/>
The property element can be used as the attribute value of a task. In a task, attribute names are placed between "$ {" and "}" and the attribute values of the task are placed.
Ant provides some built-in attributes. The list of system attributes that can be obtained is consistent with the attributes obtained by the system. getpropertis () method in the Java document,
For more information about these system attributes, see the description on the sun website. At the same time, ant also provides its own built-in attributes, as shown below:
Basedir: the absolute path of the project base directory;
Ant. File: the absolute path of buildfile. In the preceding example, the ant. File value is c: \ thinkinjavacode \ build. xml;
Ant. Version: The version information of ant. This document is 1.8.1;
Ant. Project. Name: the name of the current specified project, that is, the name attribute value of the project mentioned above;
Ant. java. Version: JDK version detected by Ant. This article is 1.6.
4. Common ant commands