Ant's config file--build.xml has the property element. And according to the offical-doc,the property has the attributes-value and location. But I don't understand why we need location? Can I set the path as a value in property? Then no need for location.
Ant properties are key, value pairs you can configure inside your Ant build script. Typically you use properties for values that you need to refer to multiple times in your Ant build script. For instance, the source directory of your Java code, or the build output directory.
Ant Properties are set once and then can never be overridden. That's why setting any property on the command line via a -Dproperty=value will always override anything you've set in the file; the property is set and then nothing can override it. This way: Anything set at the command line takes precedence over build.
The <property> task is used to set the Ant properties. The property value is immutable, once the value is set you cannot change it. To set a property to a specific value you use Name/value assignment. To set a property to a location you use Name/location assignment.
location is used if you want to do relative paths.
notice in this example, they use location. no absolute path needed. http://ant.apache.org/manual/using.html
either location or value (mutually exclusive) can be used if you're doing absolute paths
Sets the property to the absolute filename of the given file. If the value of this attribute is an absolute path, it is left unchanged (with / and \ characters converted to the current platforms conventions). Otherwise it is taken as a path relative to the project's basedir and expanded.
Source : http://ant.apache.org/manual/Tasks/property.html
Example, someone want to store lib dir path in a variable then it can be done as shown below.
<property name="lib.dir" location ="project_home/lib"/>
and you can use the above property as shown below.
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With