## Property

### Description

Sets a property (by name and value), or set of properties (from file or resource) in the project.

When a property was set by the user, or was a property in a parent project (that started this project with the ant task), then this property cannot be set, and will be ignored. This means that properties set outside the current project always override the properties of the current project.

There are five ways to set properties:

- By supplying both the name and value attribute.
- By supplying both the name and refid attribute.
- By setting the file attribute with the filename of the property file to load. This property file has the format as defined by the file used in the class java.util.Properties.
- By setting the resource attribute with the resource name of the property file to load. This property file has the format as defined by the file used in the class java.util.Properties.
- By setting the environment attribute with a prefix to use. Properties will be defined for every environment variable by prefixing the supplied name and a period to the name of the variable.

Although combinations of the three ways are possible, only one should be used at a time. Problems might occur with the order in which properties are set, for instance.

The value part of the properties being set, might contain references to other properties. These references are resolved at the time these properties are set. This also holds for properties loaded from a property file.

### Parameters

Attribute | Description | Required
name | the name of the property to set. | Yes
value | the value of the property. | Yes
refid | Reference to an object defined elsewhere. Only yields reasonable results for references to PATH like structures or properties.
resource | the resource name of the property file.
file | the filename of the property file .
location | 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.
environment | the prefix to use when retrieving environment variables. Thus if you specify environment="myenv" you will be able to access OS-specific environment variables via property names "myenv.PATH" or "myenv.TERM". Note that if you supply a property name with a final "." it will not be doubled. ie environment="myenv." will still allow access of environment variables through "myenv.PATH" and "myenv.TERM". This functionality is currently only implemented on select platforms. Feel free to send patches to increase the number of platforms this functionality is supported on ;)
classpath | the classpath to use when looking up a resource. | No
classpathref | the classpath to use when looking up a resource, given as reference to a PATH defined elsewhere.. | No

### Parameters specified as nested elements

#### classpath

`Property`'s classpath attribute is a PATH like structure and can also be set via a nested classpath element.

### Examples

      <property name="foo.dist" value="dist"/>

sets the property `foo.dist` to the value "dist".

      <property file="foo.properties"/>

reads a set of properties from a file called "foo.properties".

      <property resource="foo.properties"/>

reads a set of properties from a resource called "foo.properties".

Note that you can reference a global properties file for all of your Ant builds using the following:

      <property file="${user.home}/.ant-global.properties"/>

since the "user.home" property is defined by the Java virtual machine to be your home directory. This technique is more appropriate for Unix than Windows since the notion of a home directory doesn't exist on Windows. On the JVM that I tested, the home directory on Windows is "C:\". Different JVM implementations may use other values for the home directory on Windows.

Copyright © 2000,2001 Apache Software Foundation. All rights Reserved.