Using Ant
Projects
A project has three attributes:
name
default
basedir
The base directory from which all path calculations are done. This attribute might be overridden by setting the "basedir" property beforehand. When this is done, it must be omitted in the project tag. If neither the attribute nor the property have been set, the parent directory of the buildfile will be used.
Each project defines one or more targets. A target is a set of tasks you want to be executed. When starting Ant, you can select which target(s) you want to have executed. When no target is given, the project's default is used.
Targets
A target has the following attributes:
name
depends
a comma-separated list of names of targets on which this target depends.
if
the name of the property that must be set in order for this target to execute.
unless
the name of the property that must not be set in order for this target to execute.
description
a short description of this target's function.
A target can depend on other targets.
eg,
Explain:
Suppose we want to execute target D. From its depends attribute, you might think that first target C, then B and then A is executed. Wrong! C depends on B, and B depends on A, so first A is executed, then B, then C, and finally D.
Note: Ant will only check whether the property has been set, the value doesn't matter. A property set to the empty string is still an existing property.
eg
In the first example, if the module-A-present property is set (to any value, e.g. false), the target will be run. In the second example, if the module-A-present property is set (again, to any value), the target will not be run.
If you want to check multiple conditions, you can use a dependend target for computing the result for the check:
Files foo.txt and bar.txt are present.
Tasks
A task is a piece of code that can be executed.
Tasks have a common structure:
Properties
A project can have a set of properties.
Properties may be used in the value of task attributes. This is done by placing the property name between "${" and "}" in the attribute value. For example, if there is a "builddir" property with the value "build", then this could be used in an attribute like this: ${builddir}/classes. This is resolved at run-time as build/classes.
In the event you should need to include this construct literally (i.e. without property substitutions), simply "escape" the '$' character by doubling it. To continue the previous example: $${builddir}=${builddir}
will echo this message:
${builddir}=build/classes
Example Buildfile
simple example build file
Path-like Structures
one or more Resource Collections can be specified as nested elements (these must consist of file-type resources only). Additionally, it should be noted that although resource collections are processed in the order encountered, certain resource collection types such as fileset, dirset and files are undefined in terms of order.
This builds a path that holds the value of ${classpath}, followed by all jar files in the lib directory, the classes directory, all directories named classes under the apps subdirectory of ${build.dir}, except those that have the text Test in their name, and the files specified in the referenced FileList.
Note:
Fileset
A FileSet is a group of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of PatternSets and Selectors.
A path-like structure can include a reference to another path-like structure (a path being itself a resource collection) via nested elements:
The shortcuts previously mentioned for are also valid for .For example:
can be written as:
Typic Builder.xml of JSF
|