Project
- is the top level element in an Ant script.
- has three optional attributes:
- name the name of the project
- default the default target to use when no target is supplied
- basedir the base directory from which all path calculations are done
Target
- Each project defines zero 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 can be conditionally executed (using if/unless)
- A target can depend on other targets
- Target dependencies are transitive
Example
<target name="A" />
<target name="B" depends="A" />
<target name="C" depends="A" />
<target name="D" depends="B,C" />
Suppose we want to execute target D, which depends upon B and CC depends on AB depends on A,
so first A is executed, then B, then C, and finally D
Tasks
- A task is a piece of code that can be executed.
- A task can have multiple attributes (a.k.a arguments)
- The value of an attribute might use the value of a property.
- Ant comes with over 80 core tasks, and 60 optional tasks.
- There are over 100 third-party tools and tasks written for Ant
- Ant task extensions can be easily written for any unique problem
Properties
- A property has a name and a value; the name is case-sensitive.
- 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.
- Properties are immutable :
- whoever sets a property first freezes it for the rest of the build
- they are most definitely not variable
- they are comparable to string constants in other languages
Setting Properties - Precedence
When the same property is set in multiple places, the first definition of the property freezes the value, subsequent definition attempts fail.
The following rules are used to determine precedence:
1. Properties defined on the command line: -Dname=value
2. <property> elements under the <project> element in their written order
3. <property> elements under <target> elements in their executued order
Setting Properties - Examples
Set the property foo.dist to the value "dist":
<property name="foo.dist" value="dist"/>
Read a set of properties from a file called "foo.properties":
<property file="foo.properties"/>
Read a set of properties from a classpath resource called "foo.properties":
<property resource="foo.properties"/>
Read the system environment variables and store them in properties, prefixed with "env":
<property environment="env"/>
Built-in Properties
Ant provides access to all system properties as if they had been defined using a <property> task.
- For example, ${os.name} expands to the name of the operating system.
- For a list of system properties see the Javadoc of System.getProperties
In addition, Ant has some built-in properties :
basedir the absolute path of the project's basedir (as set with the basedir attribute of <project>)
ant.file the absolute path of the buildfile
ant.version the version of Ant
ant.project.name the name of the project that is currently executing; it is set in the name attribute of <project>
ant.java.version the JVM version Ant detected; currently it can hold the values "1.1", "1.2", "1.3", "1.4", "1.5" (and "1.6" soon).
Paths
<classpath>
<pathelement path="${classpath}" />
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<pathelement location="classes"/>
<dirset dir="${build.dir}">
<include name="apps/**/classes"/>
<exclude name="apps/**/*Test*"/>
</dirset>
<filelist refid="third-party_jars"/>
</classpath>
No comments:
Post a Comment
Note: only a member of this blog may post a comment.