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 8.0 kB

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