source: other-projects/trunk/realistic-books/packages/AntInstaller/web/manual1.6.2/manual/CoreTasks/property.html@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

File size: 8.9 KB
Line 
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
14resource) 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
36at a time. Problems might occur with the order in which properties are set, for
37instance.</p>
38<p>The value part of the properties being set, might contain references to other
39properties. These references are resolved at the time these properties are set.
40This also holds for properties loaded from a property file.</p>
41<p>A list of predefined properties can be found <a
42href="../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
46logicals on an OpenVMS system. Logicals with multiple equivalence names get
47mapped to a property whose value is a comma separated list of all equivalence
48names. If a logical is defined in multiple tables, only the most local
49definition is available (the table priority order being PROCESS, JOB, GROUP,
50SYSTEM).
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=&quot;myenv&quot; you will be able to access OS-specific
103 environment variables via property names &quot;myenv.PATH&quot; or
104 &quot;myenv.TERM&quot;. Note that if you supply a property name with a final
105 &quot;.&quot; it will not be doubled. ie environment=&quot;myenv.&quot; will still
106 allow access of environment variables through &quot;myenv.PATH&quot; and
107 &quot;myenv.TERM&quot;. 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 &lt;path&gt; 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
137href="../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> &lt;property name=&quot;foo.dist&quot; value=&quot;dist&quot;/&gt;</pre>
141<p>sets the property <code>foo.dist</code> to the value &quot;dist&quot;.</p>
142<pre> &lt;property file=&quot;foo.properties&quot;/&gt;</pre>
143<p>reads a set of properties from a file called &quot;foo.properties&quot;.</p>
144<pre> &lt;property url=&quot;http://www.mysite.com/bla/props/foo.properties&quot;/&gt;</pre>
145<p>reads a set of properties from the address &quot;http://www.mysite.com/bla/props/foo.properties&quot;.</p>
146<pre> &lt;property resource=&quot;foo.properties&quot;/&gt;</pre>
147<p>reads a set of properties from a resource called &quot;foo.properties&quot;.</p>
148<p>Note that you can reference a global properties file for all of your Ant
149builds using the following:</p>
150<pre> &lt;property file=&quot;${user.home}/.ant-global.properties&quot;/&gt;</pre>
151<p>since the &quot;user.home&quot; property is defined by the Java virtual machine
152to be your home directory. Where the &quot;user.home&quot; property resolves to in
153the file system depends on the operating system version and the JVM implementation.
154On Unix based systems, this will map to the user's home directory. On modern Windows
155variants, this will most likely resolve to the user's directory in the &quot;Documents
156and Settings&quot; folder. Older windows variants such as Windows 98/ME are less
157predictable, as are other operating system/JVM combinations.</p>
158
159<pre>
160 &lt;property environment=&quot;env&quot;/&gt;
161 &lt;echo message=&quot;Number of Processors = ${env.NUMBER_OF_PROCESSORS}&quot;/&gt;
162 &lt;echo message=&quot;ANT_HOME is set to = ${env.ANT_HOME}&quot;/&gt;
163</pre>
164<p>reads the system environment variables and stores them in properties, prefixed with &quot;env&quot;.
165Note that this only works on <em>select</em> operating systems.
166Two of the values are shown being echoed.
167</p>
168
169<h3>Property Files</h3>
170
171As stated, this task will load in a properties file stored in the file
172system, or as a resource on a classpath. Here are some interesting facts
173about this feature
174<ol>
175<li>If the file is not there, nothing is printed except at -verbose log
176level. This lets you have optional configuration files for every
177project, 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>.
180This 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>
185In-file property expansion is very cool. Learn to use it.
186<p>
187Example:
188<pre>
189build.compiler=jikes
190deploy.server=lucky
191deploy.port=8080
192deploy.url=http://${deploy.server}:${deploy.port}/
193</pre>
194
195
196<hr>
197<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
198Reserved.</p>
199</body>
200</html>
201
Note: See TracBrowser for help on using the repository browser.