You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

property.html 9.0 KiB

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