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 6.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 five 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>resource</i> attribute with the resource name of the
  21. property file to load. This property file has the format as defined by the
  22. file used in the class java.util.Properties.</li>
  23. <li>By setting the <i>environment</i> attribute with a prefix to use.
  24. Properties will be defined for every environment variable by
  25. prefixing the supplied name and a period to the name of the variable.</li>
  26. </ul>
  27. <p>Although combinations of these ways are possible, only one should be used
  28. at a time. Problems might occur with the order in which properties are set, for
  29. instance.</p>
  30. <p>The value part of the properties being set, might contain references to other
  31. properties. These references are resolved at the time these properties are set.
  32. This also holds for properties loaded from a property file.</p>
  33. <p>A list of predefined properties can be found <a
  34. href="../using.html#built-in-props">here</a>.</p>
  35. <h3>Parameters</h3>
  36. <table border="1" cellpadding="2" cellspacing="0">
  37. <tr>
  38. <td valign="top"><b>Attribute</b></td>
  39. <td valign="top"><b>Description</b></td>
  40. <td align="center" valign="top"><b>Required</b></td>
  41. </tr>
  42. <tr>
  43. <td valign="top">name</td>
  44. <td valign="top">the name of the property to set.</td>
  45. <td valign="top" align="center">No</td>
  46. </tr>
  47. <tr>
  48. <td valign="top">value</td>
  49. <td valign="top">the value of the property.</td>
  50. <td valign="middle" align="center" rowspan="3">One of these, when using the
  51. name attribute</td>
  52. </tr>
  53. <tr>
  54. <td valign="top">location</td>
  55. <td valign="top">Sets the property to the absolute filename of the
  56. given file. If the value of this attribute is an absolute path, it
  57. is left unchanged (with / and \ characters converted to the
  58. current platforms conventions). Otherwise it is taken as a path
  59. relative to the project's basedir and expanded.</td>
  60. </tr>
  61. <tr>
  62. <td valign="top">refid</td>
  63. <td valign="top"><a href="../using.html#references">Reference</a> to an object
  64. defined elsewhere. Only yields reasonable results for references
  65. to <a href="../using.html#path">PATH like structures</a> or properties.</td>
  66. </tr>
  67. <tr>
  68. <td valign="top">resource</td>
  69. <td valign="top">the resource name of the property file.</td>
  70. <td valign="middle" align="center" rowspan="3">One of these, when
  71. <b>not</b> using the name attribute</td>
  72. </tr>
  73. <tr>
  74. <td valign="top">file</td>
  75. <td valign="top">the filename of the property file .</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">environment</td>
  79. <td valign="top">the prefix to use when retrieving environment variables. Thus
  80. if you specify environment=&quot;myenv&quot; you will be able to access OS-specific
  81. environment variables via property names &quot;myenv.PATH&quot; or
  82. &quot;myenv.TERM&quot;. Note that if you supply a property name with a final
  83. &quot;.&quot; it will not be doubled. ie environment=&quot;myenv.&quot; will still
  84. allow access of environment variables through &quot;myenv.PATH&quot; and
  85. &quot;myenv.TERM&quot;. This functionality is currently only implemented
  86. on select platforms. Feel free to send patches to increase the number of platforms
  87. this functionality is supported on ;).<br>
  88. Note also that properties are case sensitive, even if the
  89. environment variables on your operating system are not, e.g. it
  90. will be ${env.Path} not ${env.PATH} on Windows 2000.</td>
  91. </tr>
  92. <tr>
  93. <td valign="top">classpath</td>
  94. <td valign="top">the classpath to use when looking up a resource.</td>
  95. <td align="center" valign="top">No</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">classpathref</td>
  99. <td valign="top">the classpath to use when looking up a resource,
  100. given as <a href="../using.html#references">reference</a> to a &lt;path&gt; defined
  101. elsewhere..</td>
  102. <td align="center" valign="top">No</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">prefix</td>
  106. <td valign="top">Prefix to apply to properties loaded using <code>file</code>
  107. or <code>resource</code>. A "." is appended to the prefix if not specified.</td>
  108. <td align="center" valign="top">No</td>
  109. </tr>
  110. </table>
  111. <h3>Parameters specified as nested elements</h3>
  112. <h4>classpath</h4>
  113. <p><code>Property</code>'s <i>classpath</i> attribute is a <a
  114. href="../using.html#path">PATH like structure</a> and can also be set via a nested
  115. <i>classpath</i> element.</p>
  116. <h3>Examples</h3>
  117. <pre> &lt;property name=&quot;foo.dist&quot; value=&quot;dist&quot;/&gt;</pre>
  118. <p>sets the property <code>foo.dist</code> to the value &quot;dist&quot;.</p>
  119. <pre> &lt;property file=&quot;foo.properties&quot;/&gt;</pre>
  120. <p>reads a set of properties from a file called &quot;foo.properties&quot;.</p>
  121. <pre> &lt;property resource=&quot;foo.properties&quot;/&gt;</pre>
  122. <p>reads a set of properties from a resource called &quot;foo.properties&quot;.</p>
  123. <p>Note that you can reference a global properties file for all of your Ant
  124. builds using the following:</p>
  125. <pre> &lt;property file=&quot;${user.home}/.ant-global.properties&quot;/&gt;</pre>
  126. <p>since the &quot;user.home&quot; property is defined by the Java virtual machine
  127. to be your home directory. This technique is more appropriate for Unix than
  128. Windows since the notion of a home directory doesn't exist on Windows. On the
  129. JVM that I tested, the home directory on Windows is &quot;C:\&quot;. Different JVM
  130. implementations may use other values for the home directory on Windows.</p>
  131. <pre>
  132. &lt;property environment=&quot;env&quot;/&gt;
  133. &lt;echo message=&quot;Number of Processors = ${env.NUMBER_OF_PROCESSORS}&quot;/&gt;
  134. &lt;echo message=&quot;ANT_HOME is set to = ${env.ANT_HOME}&quot;/&gt;
  135. </pre>
  136. <p>reads the system environment variables and stores them in properties, prefixed with &quot;env&quot;.
  137. Note that this only works on <em>select</em> operating systems.
  138. Two of the values are shown being echoed.
  139. </p>
  140. <hr>
  141. <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
  142. Reserved.</p>
  143. </body>
  144. </html>