Use Ant
1 Write a simple compilation file
The compilation file of Ant is written in XML format, each compilation file contains a Project and at least one target. Targets contain some Task elements. Each Task element can have an ID attribute (Attribute) can be used by other references.
2 Projects
A Projext can have the following properties attribute:
Attribute
Description
Whether it must
Name
project name
NO
DEFAULT
When there is no Target support, the lack of use of Target
YES.
Basedir
The base catalog, other directories are relative to this. This Attribute can be overwritten by "Basedir" Property. Basedir Attribute doesn't work when "BaseDir" Property is set. If both are set, the parent directory of the BuildFile itself is used as the base directory.
NO
You can also set the instructions for the item as needed, in the
The first Project can have one or more Targets. A Target is a series of task groups you want to perform. When running Ant, you can choose which task group is executed. If no task group is given, the project default task group is executed.
3 Targets
Target may exist in other Targets. You may use a target to compile, use another target and used to deploy. Only after compiling is completed, the deployment can be implemented, so the deployment relies on compilation.
To explain, Ant's Depends Attribute just specifies the front-rear execution relationship between Targets and does not represent real dependence.
The order of dependence is from left to right in accordance with the order of arrangement. But if these dependencies, there is still dependencies, it is also possible to execute later, as follows:
If we are going to run Target D. From its dependence on the Attribute list, you may perform C, then B, then A. In fact, this is wrong. C depends on B, B depends on A. Therefore, A is executed first, but B, then C, finally D.
A Target is only executed once, although a lot of Target may depend on it. As shown in the above example.
The Target can also determine the execution based on its Attribute settings. This allows for a better control compilation process based on the condition of the system (such as Java version, OS, command line attribute definition, etc.). This introduces an IF or UNLESS attribute (Attribute).
Note: Ant is just check whether attribute is set, without checking its value, even if the attribute value is an empty string, it still thinks this is an attribute (Attribute). E.g:
If there is no IF or UNLESS attribute (Attribute), the target will be executed.
Optional Description attributes (attribute) can be used to indicate the description of the Target of the line, can be displayed in the 'token line with the -projecthelp parameter. TARGET without Description attribute (Attribute) is considered to be internal and is not displayed unless the -verbose or -debug parameter is used.
Initialize Target, all other Targets are dependent on it. It is usually located in the first item on the list. In this manual, most initialization Targets is named with init.
Target has the following properties:
Attribute
Description
Whether it must
Name
Target's name
YES
Depends
Relying on Target list
NO
IF
To perform Target, a property (attribute) must be set
NO
Unless
To perform Target, attribute must not be set
NO
Description
Short description for Target features
NO
TARGET Name Description: You can use any character in any XML encoded alphabet, such as a null string, comma, space. But it is best to avoid using them, in order to avoid arranging, future version of Ant does not support these special characters. The naming rules of Target are related to the specific development manufacturers when the Name Rules of the Target is related to specific development manufacturers.
The Target name starting with the horizontal line, such as "-restart" is a valid naming, but cannot be used to execute in the command line.
4 Tasks
TASK is an executable code.
Task can have a variety of attributes (or parameters, as long as you like). The value of attribute may contain references to attributes. These references should be parsed before TASK execution.
The general structure of TASK is as follows:
Name is the name of Task, Attribute is the name of the attribute, and Valuen is the value of attributes.
Some are built-in tasks, while others are optional tasks, and users can freely define.
All Tasks have shared task names, and the attribute value will be used when Ant generates a message.
Task can specify an ID attribute (attribute):
TaskName is the name of Task, TaskID is a unique identity. You can reference the corresponding Task object through this name in the scriptor or other Task. E.g:
Task1.setfoo ("BAR");
script>
This allows the Foo attribute value of Task1 to be BAR; and in the Java program, the Task1 instance is accessed via Project.getReference ("Task1").
5 Properties project can have a range of properties. These may be set in the compilation file via the Property task (Task) or may be set outside ANT. A property (Property) corresponds to the name and value. The name is case sensitive. Property can be used in Task's (Attribute). Can be referenced in the "{Property name}". For example, if there is a BuildDir property (Property), the value is build, you can use this in the attribute (attribute): $ {builddir} / classes. It is converted to build / classes at runtime.
Built-in Properties
Ant provides access to all system properties, just like these system properties have been defined in the
The absolute path of the BaseDir project (just like defined in the "BaseDir property of
ANT.FILE Compilation file absolute path
Ant.Version Ant version
Ant.project.name The name of the project being executed, (like setting it in the
Ant.java.version JVM version, its value may be "1.1", "1.2", "1.3" and "1.4".
Example of compilation file:
target>
Description = "Compile the Source"> Description = "Generate the distribution"> target> Description = "Clean Up"> target> provject> Above, we define the properties (Property) to any Target's externally, Some of the Targets have given the Description so that these public Targets are listed when using the ProjectHELP option, and those TARGETs without Description are considered to be internal and not displayed. Finally, to work in Target, the Source subdirectory must have the corresponding location. Note: Two words in English are attribute Attribute, Property, is not good here. Therefore, when actually translated, the two words of the original text have also been written.