Setting properties in the build file is the first method of providing
custom properties with <property> element in an ant build file.
Unlike the <project> and <target> elements, the <property>
element is defined as a task. This means that you can include <property>
elements inside a target depending on certain conditions or depending on which
target has been selected. You can also set properties at the beginning of a
build file so that they apply to the entire build file. This means that you can
set important constant values in a central location so that they are easy to
find and change. You should remember that properties set inside a target override
any properties set at the project level. Naming again comes into this and you
should consider whether your target level properties should be identified as
such by using a prefix to avoid confusion and possible namespaces clashes.
The simplest and most obvious use of the <property> task is to set a property using a name value pair, as shown below.
You can set the value of a property to the value of another property. This can be useful if you will be referencing a verbose built-in property multiple times. This is as simple as placing a property marker in the value attribute of a <property> task as shown below in source code:
<project name="Properties" default="custom.echo" basedir=".">
Run this program on the appropriate
path, then the following output will be displayed.
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial