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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Ant User Manual</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.</p>
  11. <p>When a property was set by the user, or was a property in a parent project
  12. (that started this project with the <a href="ant.html">ant task</a>), then this
  13. property cannot be set, and will be ignored. This means that properties set
  14. outside the current project always override the properties of the current
  15. project.</p>
  16. <p>There are five ways to set properties:</p>
  17. <ul>
  18. <li>By supplying both the <i>name</i> and <i>value</i> attribute.</li>
  19. <li>By supplying both the <i>name</i> and <i>refid</i> attribute.</li>
  20. <li>By setting the <i>file</i> attribute with the filename of the property
  21. file to load. This property file has the format as defined by the file used
  22. 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 the three 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. <h3>Parameters</h3>
  37. <table border="1" cellpadding="2" cellspacing="0">
  38. <tr>
  39. <td valign="top"><b>Attribute</b></td>
  40. <td valign="top"><b>Description</b></td>
  41. <td align="center" valign="top"><b>Required</b></td>
  42. </tr>
  43. <tr>
  44. <td valign="top">name</td>
  45. <td valign="top">the name of the property to set.</td>
  46. <td valign="top" align="center">Yes</td>
  47. </tr>
  48. <tr>
  49. <td valign="top">value</td>
  50. <td valign="top">the value of the property.</td>
  51. <td valign="middle" align="center" rowspan="6">Yes</td>
  52. </tr>
  53. <tr>
  54. <td valign="top">refid</td>
  55. <td valign="top"><a href="../using.html#references">Reference</a> to an object
  56. defined elsewhere. Only yields reasonable results for references
  57. to <a href="../using.html#path">PATH like structures</a> or properties.</td>
  58. </tr>
  59. <tr>
  60. <td valign="top">resource</td>
  61. <td valign="top">the resource name of the property file.</td>
  62. </tr>
  63. <tr>
  64. <td valign="top">file</td>
  65. <td valign="top">the filename of the property file .</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">environment</td>
  77. <td valign="top">the prefix to use when retrieving environment variables. Thus
  78. if you specify environment=&quot;myenv&quot; you will be able to access OS-specific
  79. environment variables via property names &quot;myenv.PATH&quot; or
  80. &quot;myenv.TERM&quot;. Note that if you supply a property name with a final
  81. &quot;.&quot; it will not be doubled. ie environment=&quot;myenv.&quot; will still
  82. allow access of environment variables through &quot;myenv.PATH&quot; and
  83. &quot;myenv.TERM&quot;. This functionality is currently only implemented
  84. on select platforms. Feel free to send patches to increase the number of platforms
  85. this functionality is supported on ;)</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">classpath</td>
  89. <td valign="top">the classpath to use when looking up a resource.</td>
  90. <td align="center" valign="top">No</td>
  91. </tr>
  92. <tr>
  93. <td valign="top">classpathref</td>
  94. <td valign="top">the classpath to use when looking up a resource,
  95. given as <a href="../using.html#references">reference</a> to a PATH defined
  96. elsewhere..</td>
  97. <td align="center" valign="top">No</td>
  98. </tr>
  99. </table>
  100. <h3>Parameters specified as nested elements</h3>
  101. <h4>classpath</h4>
  102. <p><code>Property</code>'s <i>classpath</i> attribute is a <a
  103. href="../using.html#path">PATH like structure</a> and can also be set via a nested
  104. <i>classpath</i> element.</p>
  105. <h3>Examples</h3>
  106. <pre> &lt;property name=&quot;foo.dist&quot; value=&quot;dist&quot;/&gt;</pre>
  107. <p>sets the property <code>foo.dist</code> to the value &quot;dist&quot;.</p>
  108. <pre> &lt;property file=&quot;foo.properties&quot;/&gt;</pre>
  109. <p>reads a set of properties from a file called &quot;foo.properties&quot;.</p>
  110. <pre> &lt;property resource=&quot;foo.properties&quot;/&gt;</pre>
  111. <p>reads a set of properties from a resource called &quot;foo.properties&quot;.</p>
  112. <p>Note that you can reference a global properties file for all of your Ant
  113. builds using the following:</p>
  114. <pre> &lt;property file=&quot;${user.home}/.ant-global.properties&quot;/&gt;</pre>
  115. <p>since the &quot;user.home&quot; property is defined by the Java virtual machine
  116. to be your home directory. This technique is more appropriate for Unix than
  117. Windows since the notion of a home directory doesn't exist on Windows. On the
  118. JVM that I tested, the home directory on Windows is &quot;C:\&quot;. Different JVM
  119. implementations may use other values for the home directory on Windows.</p>
  120. <hr>
  121. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  122. Reserved.</p>
  123. </body>
  124. </html>