Ant as a programmed auxiliary tool, can be seen as a level of one level with a script. Write a build.xml, use it to help you do all kinds of small conversations, should be a simple thing. But if is a big project? If you need to write a lot of build.xml, just like other scripting languages, you must take into account a factor in maintenance and code reuse: modularity. There is a discussion on THSERVERSIDE About Ant1.6 and modular: Ant 1.6 - Finally a real build tool http://www.theserverside.com/news/thread.tss?thread_id=25195. Up to version 1.6, Ant has provided a lot of Task, which can help implement the modularity of the ANT script.
1. Property
In addition to defining individual properties, Property Task can also define multiple Property from a property definition file. Put the public properties into the property file, which load this property file in each build.xml can avoid repeat these properties in each of the build.xml.
2. ANTCALL, ANT and SUBANT
ANTCALL can be understood as a simple function call. It is clear from an example:
target>
ANTCALL>
target>
The output results are shown below:
From the above example, you can see that the target to be called, then the calling parameters are specified; in the called Target, the value of param can be referenced by a similar in a reference in the TARGET.
As for Ant Target, it is also called other Target, but that target can be in another Ant file. As for Subant? Not too clear.
3. Macrodef
AntCall is very easy to use, but when the parameters have a lot of trouble, it is very troublesome, if you want to be lazy, use macrodef. Hereinafter, the above example is rewritten with MacRodef:
4. Import
with
The effect of similar functions can be achieved, but the caller and the modulated man must still be in the same file. Ant starts import Task from 1.6 to realize code reuse: properties, task definition, task, macro. A simple example:
Common.xml: XML Version = "1.0"?>
provject>
Call.xml: XML Version = "1.0"?>