[19253] | 1 | <html>
|
---|
| 2 |
|
---|
| 3 | <head>
|
---|
| 4 | <meta http-equiv="Content-Language" content="en-us">
|
---|
| 5 | <title>Property Task</title>
|
---|
| 6 | <link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
|
---|
| 7 | </head>
|
---|
| 8 |
|
---|
| 9 | <body>
|
---|
| 10 |
|
---|
| 11 | <h2><a name="property">Property</a></h2>
|
---|
| 12 | <h3>Description</h3>
|
---|
| 13 | <p>Sets a property (by name and value), or set of properties (from file or
|
---|
| 14 | resource) in the project. Properties are case sensitive.</p>
|
---|
| 15 | Properties are immutable: whoever sets a property first freezes it for the
|
---|
| 16 | rest of the build; they are most definately not variable.
|
---|
| 17 | <p>There are six ways to set properties:</p>
|
---|
| 18 | <ul>
|
---|
| 19 | <li>By supplying both the <i>name</i> and <i>value</i> attribute.</li>
|
---|
| 20 | <li>By supplying both the <i>name</i> and <i>refid</i> attribute.</li>
|
---|
| 21 | <li>By setting the <i>file</i> attribute with the filename of the property
|
---|
| 22 | file to load. This property file has the format as defined by the file used
|
---|
| 23 | in the class java.util.Properties, with the same rules about how
|
---|
| 24 | non-ISO8859-1 characters must be escaped.</li>
|
---|
| 25 | <li>By setting the <i>url</i> attribute with the url from which to load the
|
---|
| 26 | properties. This url must be directed to a file that has the format as defined
|
---|
| 27 | by the file used in the class java.util.Properties.</li>
|
---|
| 28 | <li>By setting the <i>resource</i> attribute with the resource name of the
|
---|
| 29 | property file to load. A resource is a property file on the current
|
---|
| 30 | classpath, or on the specified classpath.</li>
|
---|
| 31 | <li>By setting the <i>environment</i> attribute with a prefix to use.
|
---|
| 32 | Properties will be defined for every environment variable by
|
---|
| 33 | prefixing the supplied name and a period to the name of the variable.</li>
|
---|
| 34 | </ul>
|
---|
| 35 | <p>Although combinations of these ways are possible, only one should be used
|
---|
| 36 | at a time. Problems might occur with the order in which properties are set, for
|
---|
| 37 | instance.</p>
|
---|
| 38 | <p>The value part of the properties being set, might contain references to other
|
---|
| 39 | properties. These references are resolved at the time these properties are set.
|
---|
| 40 | This also holds for properties loaded from a property file.</p>
|
---|
| 41 | <p>A list of predefined properties can be found <a
|
---|
| 42 | href="../using.html#built-in-props">here</a>.</p>
|
---|
| 43 |
|
---|
| 44 | <h4>OpenVMS Users</h4>
|
---|
| 45 | <p>With the <code>environment</code> attribute this task will load all defined
|
---|
| 46 | logicals on an OpenVMS system. Logicals with multiple equivalence names get
|
---|
| 47 | mapped to a property whose value is a comma separated list of all equivalence
|
---|
| 48 | names. If a logical is defined in multiple tables, only the most local
|
---|
| 49 | definition is available (the table priority order being PROCESS, JOB, GROUP,
|
---|
| 50 | SYSTEM).
|
---|
| 51 | </p>
|
---|
| 52 |
|
---|
| 53 | <h3>Parameters</h3>
|
---|
| 54 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
| 55 | <tr>
|
---|
| 56 | <td valign="top"><b>Attribute</b></td>
|
---|
| 57 | <td valign="top"><b>Description</b></td>
|
---|
| 58 | <td align="center" valign="top"><b>Required</b></td>
|
---|
| 59 | </tr>
|
---|
| 60 | <tr>
|
---|
| 61 | <td valign="top">name</td>
|
---|
| 62 | <td valign="top">the name of the property to set.</td>
|
---|
| 63 | <td valign="top" align="center">No</td>
|
---|
| 64 | </tr>
|
---|
| 65 | <tr>
|
---|
| 66 | <td valign="top">value</td>
|
---|
| 67 | <td valign="top">the value of the property.</td>
|
---|
| 68 | <td valign="middle" align="center" rowspan="3">One of these, when using the
|
---|
| 69 | name attribute</td>
|
---|
| 70 | </tr>
|
---|
| 71 | <tr>
|
---|
| 72 | <td valign="top">location</td>
|
---|
| 73 | <td valign="top">Sets the property to the absolute filename of the
|
---|
| 74 | given file. If the value of this attribute is an absolute path, it
|
---|
| 75 | is left unchanged (with / and \ characters converted to the
|
---|
| 76 | current platforms conventions). Otherwise it is taken as a path
|
---|
| 77 | relative to the project's basedir and expanded.</td>
|
---|
| 78 | </tr>
|
---|
| 79 | <tr>
|
---|
| 80 | <td valign="top">refid</td>
|
---|
| 81 | <td valign="top"><a href="../using.html#references">Reference</a> to an object
|
---|
| 82 | defined elsewhere. Only yields reasonable results for references
|
---|
| 83 | to <a href="../using.html#path">PATH like structures</a> or properties.</td>
|
---|
| 84 | </tr>
|
---|
| 85 | <tr>
|
---|
| 86 | <td valign="top">resource</td>
|
---|
| 87 | <td valign="top">the resource name of the property file.</td>
|
---|
| 88 | <td valign="middle" align="center" rowspan="4">One of these, when
|
---|
| 89 | <b>not</b> using the name attribute</td>
|
---|
| 90 | </tr>
|
---|
| 91 | <tr>
|
---|
| 92 | <td valign="top">file</td>
|
---|
| 93 | <td valign="top">the filename of the property file .</td>
|
---|
| 94 | </tr>
|
---|
| 95 | <tr>
|
---|
| 96 | <td valign="top">url</td>
|
---|
| 97 | <td valign="top">the url from which to read properties.</td>
|
---|
| 98 | </tr>
|
---|
| 99 | <tr>
|
---|
| 100 | <td valign="top">environment</td>
|
---|
| 101 | <td valign="top">the prefix to use when retrieving environment variables. Thus
|
---|
| 102 | if you specify environment="myenv" you will be able to access OS-specific
|
---|
| 103 | environment variables via property names "myenv.PATH" or
|
---|
| 104 | "myenv.TERM". Note that if you supply a property name with a final
|
---|
| 105 | "." it will not be doubled. ie environment="myenv." will still
|
---|
| 106 | allow access of environment variables through "myenv.PATH" and
|
---|
| 107 | "myenv.TERM". This functionality is currently only implemented
|
---|
| 108 | on select platforms. Feel free to send patches to increase the number of platforms
|
---|
| 109 | this functionality is supported on ;).<br>
|
---|
| 110 | Note also that properties are case sensitive, even if the
|
---|
| 111 | environment variables on your operating system are not, e.g. it
|
---|
| 112 | will be ${env.Path} not ${env.PATH} on Windows 2000.</td>
|
---|
| 113 |
|
---|
| 114 | </tr>
|
---|
| 115 | <tr>
|
---|
| 116 | <td valign="top">classpath</td>
|
---|
| 117 | <td valign="top">the classpath to use when looking up a resource.</td>
|
---|
| 118 | <td align="center" valign="top">No</td>
|
---|
| 119 | </tr>
|
---|
| 120 | <tr>
|
---|
| 121 | <td valign="top">classpathref</td>
|
---|
| 122 | <td valign="top">the classpath to use when looking up a resource,
|
---|
| 123 | given as <a href="../using.html#references">reference</a> to a <path> defined
|
---|
| 124 | elsewhere..</td>
|
---|
| 125 | <td align="center" valign="top">No</td>
|
---|
| 126 | </tr>
|
---|
| 127 | <tr>
|
---|
| 128 | <td valign="top">prefix</td>
|
---|
| 129 | <td valign="top">Prefix to apply to properties loaded using <code>file</code>
|
---|
| 130 | or <code>resource</code>. A "." is appended to the prefix if not specified.</td>
|
---|
| 131 | <td align="center" valign="top">No</td>
|
---|
| 132 | </tr>
|
---|
| 133 | </table>
|
---|
| 134 | <h3>Parameters specified as nested elements</h3>
|
---|
| 135 | <h4>classpath</h4>
|
---|
| 136 | <p><code>Property</code>'s <i>classpath</i> attribute is a <a
|
---|
| 137 | href="../using.html#path">PATH like structure</a> and can also be set via a nested
|
---|
| 138 | <i>classpath</i> element.</p>
|
---|
| 139 | <h3>Examples</h3>
|
---|
| 140 | <pre> <property name="foo.dist" value="dist"/></pre>
|
---|
| 141 | <p>sets the property <code>foo.dist</code> to the value "dist".</p>
|
---|
| 142 | <pre> <property file="foo.properties"/></pre>
|
---|
| 143 | <p>reads a set of properties from a file called "foo.properties".</p>
|
---|
| 144 | <pre> <property url="http://www.mysite.com/bla/props/foo.properties"/></pre>
|
---|
| 145 | <p>reads a set of properties from the address "http://www.mysite.com/bla/props/foo.properties".</p>
|
---|
| 146 | <pre> <property resource="foo.properties"/></pre>
|
---|
| 147 | <p>reads a set of properties from a resource called "foo.properties".</p>
|
---|
| 148 | <p>Note that you can reference a global properties file for all of your Ant
|
---|
| 149 | builds using the following:</p>
|
---|
| 150 | <pre> <property file="${user.home}/.ant-global.properties"/></pre>
|
---|
| 151 | <p>since the "user.home" property is defined by the Java virtual machine
|
---|
| 152 | to be your home directory. Where the "user.home" property resolves to in
|
---|
| 153 | the file system depends on the operating system version and the JVM implementation.
|
---|
| 154 | On Unix based systems, this will map to the user's home directory. On modern Windows
|
---|
| 155 | variants, this will most likely resolve to the user's directory in the "Documents
|
---|
| 156 | and Settings" folder. Older windows variants such as Windows 98/ME are less
|
---|
| 157 | predictable, as are other operating system/JVM combinations.</p>
|
---|
| 158 |
|
---|
| 159 | <pre>
|
---|
| 160 | <property environment="env"/>
|
---|
| 161 | <echo message="Number of Processors = ${env.NUMBER_OF_PROCESSORS}"/>
|
---|
| 162 | <echo message="ANT_HOME is set to = ${env.ANT_HOME}"/>
|
---|
| 163 | </pre>
|
---|
| 164 | <p>reads the system environment variables and stores them in properties, prefixed with "env".
|
---|
| 165 | Note that this only works on <em>select</em> operating systems.
|
---|
| 166 | Two of the values are shown being echoed.
|
---|
| 167 | </p>
|
---|
| 168 |
|
---|
| 169 | <h3>Property Files</h3>
|
---|
| 170 |
|
---|
| 171 | As stated, this task will load in a properties file stored in the file
|
---|
| 172 | system, or as a resource on a classpath. Here are some interesting facts
|
---|
| 173 | about this feature
|
---|
| 174 | <ol>
|
---|
| 175 | <li>If the file is not there, nothing is printed except at -verbose log
|
---|
| 176 | level. This lets you have optional configuration files for every
|
---|
| 177 | project, that team members can customize.
|
---|
| 178 | <li>The rules for this format are laid down
|
---|
| 179 | <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#load(java.io.InputStream)">by Sun</a>.
|
---|
| 180 | This makes it hard for Team Ant to field bug reports about it.
|
---|
| 181 | <li>Trailing spaces are not stripped. It may have been what you wanted.
|
---|
| 182 | <li>Want unusual characters? Escape them \u0456 or \" style.
|
---|
| 183 | <li>Ant Properties are expanded in the file.
|
---|
| 184 | </ol>
|
---|
| 185 | In-file property expansion is very cool. Learn to use it.
|
---|
| 186 | <p>
|
---|
| 187 | Example:
|
---|
| 188 | <pre>
|
---|
| 189 | build.compiler=jikes
|
---|
| 190 | deploy.server=lucky
|
---|
| 191 | deploy.port=8080
|
---|
| 192 | deploy.url=http://${deploy.server}:${deploy.port}/
|
---|
| 193 | </pre>
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | <hr>
|
---|
| 197 | <p align="center">Copyright © 2000-2004 The Apache Software Foundation. All rights
|
---|
| 198 | Reserved.</p>
|
---|
| 199 | </body>
|
---|
| 200 | </html>
|
---|
| 201 |
|
---|