source: release-kits/lirk3/bin/ant-installer/web/manual/manual/using.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 29.9 KB
Line 
1<!--
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<html>
18
19<head>
20<meta http-equiv="Content-Language" content="en-us">
21<link rel="stylesheet" type="text/css" href="stylesheets/style.css">
22<title>Writing a Simple Buildfile</title>
23</head>
24
25<body>
26<h1>Using Ant</h1>
27<h2><a name="buildfile">Writing a Simple Buildfile</a></h2>
28<p>Ant's buildfiles are written in XML. Each buildfile contains one project
29and at least one (default) target. Targets contain task elements.
30Each task element of the buildfile can have an <code>id</code> attribute and
31can later be referred to by the value supplied to this. The value has
32to be unique. (For additional information, see the
33<a href="#tasks"> Tasks</a> section below.)</p>
34<h3><a name="projects">Projects</a></h3>
35<p>A <i>project</i> has three attributes:</p>
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 project.</td>
45 <td align="center" valign="top">No</td>
46 </tr>
47 <tr>
48 <td valign="top">default</td>
49 <td valign="top">the default target to use when no target is supplied.</td>
50 <td align="center" valign="top">No; however, <b>since Ant 1.6.0</b>,
51 every project includes an implicit target that contains any and
52 all top-level tasks and/or types. This target will always be
53 executed as part of the project's initialization, even when Ant is
54 run with the <a href="running.html#options">-projecthelp</a> option.
55 </td>
56 </tr>
57 <tr>
58 <td valign="top">basedir</td>
59 <td valign="top">the base directory from which all path calculations are
60 done. This attribute might be overridden by setting
61 the &quot;basedir&quot;
62 property beforehand. When this is done, it must be omitted in the
63 project tag. If neither the attribute nor the property have
64 been set, the parent directory of the buildfile will be used.</td>
65 <td align="center" valign="top">No</td>
66 </tr>
67</table>
68<p>Optionally, a description for the project can be provided as a
69top-level <code>&lt;description&gt;</code> element (see the <a
70href="CoreTypes/description.html">description</a> type).</p>
71
72<p>Each project defines one or more <i>targets</i>.
73A target is a set of <i>tasks</i> you want
74to be executed. When starting Ant, you can select which target(s) you
75want to have executed. When no target is given,
76the project's default is used.</p>
77
78<h3><a name="targets">Targets</a></h3>
79<p>A target can depend on other targets. You might have a target for compiling,
80for example, and a target for creating a distributable. You can only build a
81distributable when you have compiled first, so the distribute target
82<i>depends on</i> the compile target. Ant resolves these dependencies.</p>
83<p>It should be noted, however, that Ant's <code>depends</code> attribute
84only specifies the <i>order</i> in which targets should be executed - it
85does not affect whether the target that specifies the dependency(s) gets
86executed if the dependent target(s) did not (need to) run.
87</p>
88<p>Ant tries to execute the targets in the <code>depends</code>
89attribute in the order
90they appear (from left to right). Keep in mind that it is possible that a target
91can get executed earlier when an earlier target depends on it:</p>
92<blockquote>
93<pre>&lt;target name=&quot;A&quot;/&gt;
94&lt;target name=&quot;B&quot; depends=&quot;A&quot;/&gt;
95&lt;target name=&quot;C&quot; depends=&quot;B&quot;/&gt;
96&lt;target name=&quot;D&quot; depends=&quot;C,B,A&quot;/&gt;</pre>
97</blockquote>
98<p>Suppose we want to execute target D. From its
99<code>depends</code> attribute, you
100might think that first target C, then B and then A is executed.
101Wrong! C depends on B, and B depends on A, so first A is executed, then B, then C, and finally D.</p>
102<p>In a chain of dependencies stretching back from a given target such
103as D above, each target gets executed only once, even when more than
104one target depends on it. Thus, executing the D target will first
105result in C being called, which in turn will first call B, which in
106turn will first call A. After A, then B, then C have executed,
107execution returns to the dependency list of D, which will <u>not</u>
108call B and A, since they were already called in process of dependency
109resolution for C and B respectively as dependencies of D. Had no such
110dependencies been discovered in processing C and B, B and A would
111have been executed after C in processing D's dependency list.</p>
112<p>A target also has the ability to perform its execution if (or
113unless) a property has been set. This allows, for example, better
114control on the building process depending on the state of the system
115(java version, OS, command-line property defines, etc.). To make a target
116<i>sense</i> this property, you should add the <code>if</code> (or
117<code>unless</code>) attribute with the name of the property that the target
118should react to. <strong>Note:</strong> Ant will only check whether
119the property has been set, the value doesn't matter. A property set
120to the empty string is still an existing property. For example:</p>
121<blockquote>
122 <pre>&lt;target name=&quot;build-module-A&quot; if=&quot;module-A-present&quot;/&gt;</pre>
123 <pre>&lt;target name=&quot;build-own-fake-module-A&quot; unless=&quot;module-A-present&quot;/&gt;</pre>
124</blockquote>
125<p>In the first example, if the <code>module-A-present</code>
126property is set (to any value, e.g. <i>false</i>), the target will be run. In the second
127example, if the <code>module-A-present</code> property is set
128(again, to any value), the target will not be run.
129</p>
130<p>Only one propertyname can be specified in the if/unless clause. If you want to check
131multiple conditions, you can use a dependend target for computing the result for the check:</p>
132<blockquote><pre>
133&lt;target name="myTarget" depends="myTarget.check" if="myTarget.run"&gt;
134 &lt;echo&gt;Files foo.txt and bar.txt are present.&lt;/echo&gt;
135&lt/target&gt;
136
137&lt;target name="myTarget.check"&gt;
138 &lt;condition property="myTarget.run"&gt;
139 &lt;and&gt;
140 &lt;available file="foo.txt"/&gt;
141 &lt;available file="bar.txt"/&gt;
142 &lt;/and&gt;
143 &lt;/condition&gt;
144&lt/target&gt;
145</pre></blockquote>
146<p>If no <code>if</code> and no <code>unless</code> attribute is present,
147the target will always be executed.</p>
148
149<p>
150<b>Important:</b> the <code>if</code> and <code>unless</code> attributes only
151enable or disable the target to which they are attached. They do not control
152whether or not targets that a conditional target depends upon get executed.
153In fact, they do not even get evaluated until the target is about to be executed,
154and all its predecessors have already run.
155
156<p>The optional <code>description</code> attribute can be used to provide a one-line description of this target, which is printed by the
157<nobr><code>-projecthelp</code></nobr> command-line option. Targets
158without such a description are deemed internal and will not be listed,
159unless either the <nobr><code>-verbose</code></nobr> or
160<nobr><code>-debug</code></nobr> option is used.
161</p>
162<p>It is a good practice to place your <a
163href="CoreTasks/tstamp.html">tstamp</a> tasks in a so-called
164<i>initialization</i> target, on which
165all other targets depend. Make sure that target is always the first one in
166the depends list of the other targets. In this manual, most initialization targets
167have the name <code>&quot;init&quot;</code>.</p>
168<p>If the depends attribute and the if/unless attribute are set, the depends attribute is
169executed first.</p>
170<p>A target has the following attributes:</p>
171<table border="1" cellpadding="2" cellspacing="0">
172 <tr>
173 <td valign="top"><b>Attribute</b></td>
174 <td valign="top"><b>Description</b></td>
175 <td align="center" valign="top"><b>Required</b></td>
176 </tr>
177 <tr>
178 <td valign="top">name</td>
179 <td valign="top">the name of the target.</td>
180 <td align="center" valign="top">Yes</td>
181 </tr>
182 <tr>
183 <td valign="top">depends</td>
184 <td valign="top">a comma-separated list of names of targets on which this
185 target depends.</td>
186 <td align="center" valign="top">No</td>
187 </tr>
188 <tr>
189 <td valign="top">if</td>
190 <td valign="top">the name of the property that must be set in order for this
191 target to execute.</td>
192 <td align="center" valign="top">No</td>
193 </tr>
194 <tr>
195 <td valign="top">unless</td>
196 <td valign="top">the name of the property that must not be set in order
197 for this target to execute.</td>
198 <td align="center" valign="top">No</td>
199 </tr>
200 <tr>
201 <td valign="top">description</td>
202 <td valign="top">a short description of this target's function.</td>
203 <td align="center" valign="top">No</td>
204 </tr>
205</table>
206</p>
207
208<p>A target name can be any alphanumeric string valid in the encoding of the XML
209file. The empty string &quot;&quot; is in this set, as is
210comma &quot;,&quot; and space &quot; &quot;.
211Please avoid using these, as they will not be supported in future Ant versions
212because of all the confusion they cause. IDE support of unusual target names,
213or any target name containing spaces, varies with the IDE.</p>
214
215<p>Targets beginning with a hyphen such as <code>&quot;-restart&quot;</code>
216are valid, and can be used
217to name targets that should not be called directly from the command line.</p>
218
219<h3><a name="tasks">Tasks</a></h3>
220<p>A task is a piece of code that can be executed.</p>
221<p>A task can have multiple attributes (or arguments, if you prefer). The value
222of an attribute might contain references to a property. These references will be
223resolved before the task is executed.</p>
224<p>Tasks have a common structure:</p>
225<blockquote>
226 <pre>&lt;<i>name</i> <i>attribute1</i>=&quot;<i>value1</i>&quot; <i>attribute2</i>=&quot;<i>value2</i>&quot; ... /&gt;</pre>
227</blockquote>
228<p>where <i>name</i> is the name of the task,
229<i>attributeN</i> is the attribute name, and
230<i>valueN</i> is the value for this attribute.</p>
231<p>There is a set of <a href="coretasklist.html" target="navFrame">built-in tasks</a>, along with a
232number of
233<a href="optionaltasklist.html" target="navFrame"> optional tasks</a>, but it is also very
234easy to <a href="develop.html#writingowntask">write your own</a>.</p>
235<p>All tasks share a task name attribute. The value of
236this attribute will be used in the logging messages generated by
237Ant.</p>
238Tasks can be assigned an <code>id</code> attribute:
239<blockquote>
240<pre>&lt;<i>taskname</i> id="<i>taskID</i>" ... /&gt;</pre>
241</blockquote>
242where <i>taskname</i> is the name of the task, and <i>taskID</i> is
243a unique identifier for this task.
244You can refer to the
245corresponding task object in scripts or other tasks via this name.
246For example, in scripts you could do:
247<blockquote>
248<pre>
249&lt;script ... &gt;
250 task1.setFoo("bar");
251&lt;/script&gt;
252</pre>
253</blockquote>
254to set the <code>foo</code> attribute of this particular task instance.
255In another task (written in Java), you can access the instance via
256<code>project.getReference("task1")</code>.
257<p>
258Note<sup>1</sup>: If &quot;task1&quot; has not been run yet, then
259it has not been configured (ie., no attributes have been set), and if it is
260going to be configured later, anything you've done to the instance may
261be overwritten.
262</p>
263<p>
264Note<sup>2</sup>: Future versions of Ant will most likely <i>not</i>
265be backward-compatible with this behaviour, since there will likely be no
266task instances at all, only proxies.
267</p>
268
269<h3><a name="properties">Properties</a></h3>
270<p>A project can have a set of properties. These might be set in the buildfile
271by the <a href="CoreTasks/property.html">property</a> task, or might be set outside Ant. A
272property has a name and a value; the name is case-sensitive. Properties may be used in the value of
273task attributes. This is done by placing the property name between
274&quot;<code>${</code>&quot; and &quot;<code>}</code>&quot; in the
275attribute value. For example,
276if there is a &quot;builddir&quot; property with the value
277&quot;build&quot;, then this could be used in an attribute like this:
278<code>${builddir}/classes</code>.
279This is resolved at run-time as <code>build/classes</code>.</p>
280<p>In the event you should need to include this construct literally
281(i.e. without property substitutions), simply "escape" the '$' character
282by doubling it. To continue the previous example:
283<pre> &lt;echo&gt;$${builddir}=${builddir}&lt;/echo&gt;</pre>
284will echo this message:
285<pre> ${builddir}=build/classes</pre></p>
286<p>In order to maintain backward compatibility with older Ant releases,
287a single '$' character encountered apart from a property-like construct
288(including a matched pair of french braces) will be interpreted literally;
289that is, as '$'. The "correct" way to specify this literal character,
290however, is by using the escaping mechanism unconditionally, so that "$$"
291is obtained by specifying "$$$$". Mixing the two approaches yields
292unpredictable results, as "$$$" results in "$$".</p>
293
294<h3><a name="built-in-props">Built-in Properties</a></h3>
295<p>Ant provides access to all system properties as if they had been
296defined using a <code>&lt;property&gt;</code> task.
297For example, <code>${os.name}</code> expands to the
298name of the operating system.</p>
299<p>For a list of system properties see
300<a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/System.html#getProperties()">the Javadoc of System.getProperties</a>.
301</p>
302<p>In addition, Ant has some built-in properties:</p>
303<pre>
304basedir the absolute path of the project's basedir (as set
305 with the basedir attribute of <a href="#projects">&lt;project&gt;)</a>.
306ant.file the absolute path of the buildfile.
307ant.version the version of Ant
308ant.project.name the name of the project that is currently executing;
309 it is set in the name attribute of &lt;project&gt;.
310ant.java.version the JVM version Ant detected; currently it can hold
311 the values &quot;1.2&quot;, &quot;1.3&quot;, &quot;1.4&quot; and &quot;1.5&quot;.
312</pre>
313<p>There is also another property, but this is set by the launcher script and therefore
314maybe not set inside IDEs:</p>
315<pre>
316ant.home home directory of Ant
317</pre>
318
319<a name="example"><h3>Example Buildfile</h3></a>
320<pre>
321&lt;project name=&quot;MyProject&quot; default=&quot;dist&quot; basedir=&quot;.&quot;&gt;
322 &lt;description&gt;
323 simple example build file
324 &lt;/description&gt;
325 &lt;!-- set global properties for this build --&gt;
326 &lt;property name=&quot;src&quot; location=&quot;src&quot;/&gt;
327 &lt;property name=&quot;build&quot; location=&quot;build&quot;/&gt;
328 &lt;property name=&quot;dist&quot; location=&quot;dist&quot;/&gt;
329
330 &lt;target name=&quot;init&quot;&gt;
331 &lt;!-- Create the time stamp --&gt;
332 &lt;tstamp/&gt;
333 &lt;!-- Create the build directory structure used by compile --&gt;
334 &lt;mkdir dir=&quot;${build}&quot;/&gt;
335 &lt;/target&gt;
336
337 &lt;target name=&quot;compile&quot; depends=&quot;init&quot;
338 description=&quot;compile the source &quot; &gt;
339 &lt;!-- Compile the java code from ${src} into ${build} --&gt;
340 &lt;javac srcdir=&quot;${src}&quot; destdir=&quot;${build}&quot;/&gt;
341 &lt;/target&gt;
342
343 &lt;target name=&quot;dist&quot; depends=&quot;compile&quot;
344 description=&quot;generate the distribution&quot; &gt;
345 &lt;!-- Create the distribution directory --&gt;
346 &lt;mkdir dir=&quot;${dist}/lib&quot;/&gt;
347
348 &lt;!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --&gt;
349 &lt;jar jarfile=&quot;${dist}/lib/MyProject-${DSTAMP}.jar&quot; basedir=&quot;${build}&quot;/&gt;
350 &lt;/target&gt;
351
352 &lt;target name=&quot;clean&quot;
353 description=&quot;clean up&quot; &gt;
354 &lt;!-- Delete the ${build} and ${dist} directory trees --&gt;
355 &lt;delete dir=&quot;${build}&quot;/&gt;
356 &lt;delete dir=&quot;${dist}&quot;/&gt;
357 &lt;/target&gt;
358&lt;/project&gt;
359</pre>
360
361<p>Notice that we are declaring properties outside any target. As of
362Ant 1.6 all tasks can be declared outside targets (earlier version
363only allowed <tt>&lt;property&gt;</tt>,<tt>&lt;typedef&gt;</tt> and
364<tt>&lt;taskdef&gt;</tt>). When you do this they are evaluated before
365any targets are executed. Some tasks will generate build failures if
366they are used outside of targets as they may cause infinite loops
367otherwise (<code>&lt;antcall&gt;</code> for example).</p>
368
369<p>
370We have given some targets descriptions; this causes the <tt>projecthelp</tt>
371invocation option to list them as public targets with the descriptions; the
372other target is internal and not listed.
373<p>
374Finally, for this target to work the source in the <tt>src</tt> subdirectory
375should be stored in a directory tree which matches the package names. Check the
376<tt>&lt;javac&gt;</tt> task for details.
377
378<a name="filters"><h3>Token Filters</h3></a>
379<p>A project can have a set of tokens that might be automatically expanded if
380found when a file is copied, when the filtering-copy behavior is selected in the
381tasks that support this. These might be set in the buildfile
382by the <a href="CoreTasks/filter.html">filter</a> task.</p>
383<p>Since this can potentially be a very harmful behavior,
384the tokens in the files <b>must</b>
385be of the form <code>@</code><i>token</i><code>@</code>, where
386<i>token</i> is the token name that is set
387in the <code>&lt;filter&gt;</code> task. This token syntax matches the syntax of other build systems
388that perform such filtering and remains sufficiently orthogonal to most
389programming and scripting languages, as well as with documentation systems.</p>
390<p>Note: If a token with the format <code>@</code><i>token</i><code>@</code>
391is found in a file, but no
392filter is associated with that token, no changes take place;
393therefore, no escaping
394method is available - but as long as you choose appropriate names for your
395tokens, this should not cause problems.</p>
396<p><b>Warning:</b> If you copy binary files with filtering turned on, you can corrupt the
397files. This feature should be used with text files <em>only</em>.</p>
398
399<h3><a name="path">Path-like Structures</a></h3>
400<p>You can specify <code>PATH</code>- and <code>CLASSPATH</code>-type
401references using both
402&quot;<code>:</code>&quot; and &quot;<code>;</code>&quot; as separator
403characters. Ant will
404convert the separator to the correct character of the current operating
405system.</p>
406<p>Wherever path-like values need to be specified, a nested element can
407be used. This takes the general form of:</p>
408<pre>
409 &lt;classpath&gt;
410 &lt;pathelement path=&quot;${classpath}&quot;/&gt;
411 &lt;pathelement location=&quot;lib/helper.jar&quot;/&gt;
412 &lt;/classpath&gt;
413</pre>
414<p>The <code>location</code> attribute specifies a single file or
415directory relative to the project's base directory (or an absolute
416filename), while the <code>path</code> attribute accepts colon-
417or semicolon-separated lists of locations. The <code>path</code>
418attribute is intended to be used with predefined paths - in any other
419case, multiple elements with <code>location</code> attributes should be
420preferred.</p>
421<p>As a shortcut, the <code>&lt;classpath&gt;</code> tag
422supports <code>path</code> and
423<code>location</code> attributes of its own, so:</p>
424<pre>
425 &lt;classpath&gt;
426 &lt;pathelement path=&quot;${classpath}&quot;/&gt;
427 &lt;/classpath&gt;
428</pre>
429<p>can be abbreviated to:</p>
430<pre>
431 &lt;classpath path=&quot;${classpath}&quot;/&gt;
432</pre>
433<p>In addition, one or more
434<a href="CoreTypes/resources.html#collection">Resource Collection</a>s
435can be specified as nested elements (these must consist of
436<a href="CoreTypes/resources.html#file">file</a>-type resources only).
437Additionally, it should be noted that although resource collections are
438processed in the order encountered, certain resource collection types
439such as <a href="CoreTypes/fileset.html">fileset</a>,
440<a href="CoreTypes/dirset.html">dirset</a> and
441<a href="CoreTypes/resources.html#files">files</a>
442are undefined in terms of order.</p>
443<pre>
444 &lt;classpath&gt;
445 &lt;pathelement path=&quot;${classpath}&quot;/&gt;
446 &lt;fileset dir=&quot;lib&quot;&gt;
447 &lt;include name=&quot;**/*.jar&quot;/&gt;
448 &lt;/fileset&gt;
449 &lt;pathelement location=&quot;classes&quot;/&gt;
450 &lt;dirset dir=&quot;${build.dir}&quot;&gt;
451 &lt;include name=&quot;apps/**/classes&quot;/&gt;
452 &lt;exclude name=&quot;apps/**/*Test*&quot;/&gt;
453 &lt;/dirset&gt;
454 &lt;filelist refid=&quot;third-party_jars&quot;/&gt;
455 &lt;/classpath&gt;
456</pre>
457<p>This builds a path that holds the value of <code>${classpath}</code>,
458followed by all jar files in the <code>lib</code> directory,
459the <code>classes</code> directory, all directories named
460<code>classes</code> under the <code>apps</code> subdirectory of
461<code>${build.dir}</code>, except those
462that have the text <code>Test</code> in their name, and
463the files specified in the referenced FileList.</p>
464<p>If you want to use the same path-like structure for several tasks,
465you can define them with a <code>&lt;path&gt;</code> element at the
466same level as <i>target</i>s, and reference them via their
467<i>id</i> attribute--see <a href="#references">References</a> for an
468example.</p>
469<p>A path-like structure can include a reference to another path-like
470structure (a path being itself a resource collection)
471via nested <code>&lt;path&gt;</code> elements:</p>
472<pre>
473 &lt;path id=&quot;base.path&quot;&gt;
474 &lt;pathelement path=&quot;${classpath}&quot;/&gt;
475 &lt;fileset dir=&quot;lib&quot;&gt;
476 &lt;include name=&quot;**/*.jar&quot;/&gt;
477 &lt;/fileset&gt;
478 &lt;pathelement location=&quot;classes&quot;/&gt;
479 &lt;/path&gt;
480
481 &lt;path id=&quot;tests.path&quot;&gt;
482 &lt;path refid=&quot;base.path&quot;/&gt;
483 &lt;pathelement location=&quot;testclasses&quot;/&gt;
484 &lt;/path&gt;
485</pre>
486 The shortcuts previously mentioned for <code>&lt;classpath&gt;</code> are also valid for <code>&lt;path&gt;</code>.For example:
487<pre>
488 &lt;path id=&quot;base.path&quot;&gt;
489 &lt;pathelement path=&quot;${classpath}&quot;/&gt;
490 &lt;/path&gt;
491</pre>
492can be written as:
493<pre>
494 &lt;path id=&quot;base.path&quot; path=&quot;${classpath}&quot;/&gt;
495</pre>
496
497<h3><a name="arg">Command-line Arguments</a></h3>
498<p>Several tasks take arguments that will be passed to another
499process on the command line. To make it easier to specify arguments
500that contain space characters, nested <code>arg</code> elements can be used.</p>
501<table border="1" cellpadding="2" cellspacing="0">
502<tr>
503 <td width="12%" valign="top"><b>Attribute</b></td>
504 <td width="78%" valign="top"><b>Description</b></td>
505 <td width="10%" valign="top"><b>Required</b></td>
506</tr>
507 <tr>
508 <td valign="top">value</td>
509 <td valign="top">a single command-line argument; can contain space
510 characters.</td>
511 <td align="center" rowspan="5">Exactly one of these.</td>
512 </tr>
513 <tr>
514 <td valign="top">file</td>
515 <td valign="top">The name of a file as a single command-line
516 argument; will be replaced with the absolute filename of the file.</td>
517 </tr>
518 <tr>
519 <td valign="top">path</td>
520 <td valign="top">A string that will be treated as a path-like
521 string as a single command-line argument; you can use <code>;</code>
522 or <code>:</code> as
523 path separators and Ant will convert it to the platform's local
524 conventions.</td>
525 </tr>
526 <tr>
527 <td valign="top">pathref</td>
528 <td valign="top"><a href="#references">Reference</a> to a path
529 defined elsewhere. Ant will convert it to the platform's local
530 conventions.</td>
531 </tr>
532 <tr>
533 <td valign="top">line</td>
534 <td valign="top">a space-delimited list of command-line arguments.</td>
535 </tr>
536</table>
537
538<p>It is highly recommended to avoid the <code>line</code> version
539when possible. Ant will try to split the command line in a way
540similar to what a (Unix) shell would do, but may create something that
541is very different from what you expect under some circumstances.</p>
542
543<h4>Examples</h4>
544<blockquote><pre>
545 &lt;arg value=&quot;-l -a&quot;/&gt;
546</pre></blockquote>
547<p>is a single command-line argument containing a space character,
548<i>not</i> separate commands "-l" and "-a".</p>
549<blockquote><pre>
550 &lt;arg line=&quot;-l -a&quot;/&gt;
551</pre></blockquote>
552<p>This is a command line with two separate arguments, "-l" and "-a".</p>
553<blockquote><pre>
554 &lt;arg path=&quot;/dir;/dir2:\dir3&quot;/&gt;
555</pre></blockquote>
556<p>is a single command-line argument with the value
557<code>\dir;\dir2;\dir3</code> on DOS-based systems and
558<code>/dir:/dir2:/dir3</code> on Unix-like systems.</p>
559
560<h3><a name="references">References</a></h3>
561
562<p>Any project element can be assigned an identifier using its
563<code>id</code> attribute. In most cases the element can subsequently
564be referenced by specifying the <code>refid</code> attribute on an
565element of the same type. This can be useful if you are going to
566replicate the same snippet of XML over and over again--using a
567<code>&lt;classpath&gt;</code> structure more than once, for example.</p>
568<p>The following example:</p>
569<blockquote><pre>
570&lt;project ... &gt;
571 &lt;target ... &gt;
572 &lt;rmic ...&gt;
573 &lt;classpath&gt;
574 &lt;pathelement location=&quot;lib/&quot;/&gt;
575 &lt;pathelement path=&quot;${java.class.path}/&quot;/&gt;
576 &lt;pathelement path=&quot;${additional.path}&quot;/&gt;
577 &lt;/classpath&gt;
578 &lt;/rmic&gt;
579 &lt;/target&gt;
580
581 &lt;target ... &gt;
582 &lt;javac ...&gt;
583 &lt;classpath&gt;
584 &lt;pathelement location=&quot;lib/&quot;/&gt;
585 &lt;pathelement path=&quot;${java.class.path}/&quot;/&gt;
586 &lt;pathelement path=&quot;${additional.path}&quot;/&gt;
587 &lt;/classpath&gt;
588 &lt;/javac&gt;
589 &lt;/target&gt;
590&lt;/project&gt;
591</pre></blockquote>
592<p>could be rewritten as:</p>
593<blockquote><pre>
594&lt;project ... &gt;
595 &lt;path id=&quot;project.class.path&quot;&gt;
596 &lt;pathelement location=&quot;lib/&quot;/&gt;
597 &lt;pathelement path=&quot;${java.class.path}/&quot;/&gt;
598 &lt;pathelement path=&quot;${additional.path}&quot;/&gt;
599 &lt;/path&gt;
600
601 &lt;target ... &gt;
602 &lt;rmic ...&gt;
603 &lt;classpath refid=&quot;project.class.path&quot;/&gt;
604 &lt;/rmic&gt;
605 &lt;/target&gt;
606
607 &lt;target ... &gt;
608 &lt;javac ...&gt;
609 &lt;classpath refid=&quot;project.class.path&quot;/&gt;
610 &lt;/javac&gt;
611 &lt;/target&gt;
612&lt;/project&gt;
613</pre></blockquote>
614<p>All tasks that use nested elements for
615<a href="CoreTypes/patternset.html">PatternSet</a>s,
616<a href="CoreTypes/fileset.html">FileSet</a>s,
617<a href="CoreTypes/zipfileset.html">ZipFileSet</a>s or
618<a href="#path">path-like structures</a> accept references to these structures
619as shown in the examples. Using <code>refid</code> on a task will ordinarily
620have the same effect (referencing a task already declared), but the user
621should be aware that the interpretation of this attribute is dependent on the
622implementation of the element upon which it is specified. Some tasks (the
623<a href="CoreTasks/property.html">property</a> task is a handy example)
624deliberately assign a different meaning to <code>refid</code>.</p>
625
626
627<h3><a name="external-tasks">Use of external tasks</a></h3>
628Ant supports a plugin mechanism for using third party tasks. For using them you
629have to do two steps:
630<ol>
631 <li>place their implementation somewhere where Ant can find them</li>
632 <li>declare them.</li>
633</ol>
634Don't add anything to the CLASSPATH environment variable - this is often the
635reason for very obscure errors. Use Ant's own <a href="install.html#optionalTasks">mechanisms</a>
636for adding libraries:
637<ul>
638 <li>via command line argument <code>-lib</code></li>
639 <li>adding to <code>${user.home}/.ant/lib</code></li>
640 <li>adding to <code>${ant.home}/lib</code></li>
641</ul>
642For the declaration there are several ways:
643<ul>
644 <li>declare a single task per using instruction using
645 <code>&lt;<a href="CoreTasks/taskdef.html">taskdef</a> name=&quot;taskname&quot;
646 classname=&quot;ImplementationClass&quot;/&gt;</code>
647 <br>
648 <code>&lt;taskdef name=&quot;for&quot; classname=&quot;net.sf.antcontrib.logic.For&quot; /&gt;
649 &lt;for ... /&gt;</code>
650 </li>
651 <li>declare a bundle of tasks using a properties-file holding these
652 taskname-ImplementationClass-pairs and <code>&lt;taskdef&gt;</code>
653 <br>
654 <code>&lt;taskdef resource=&quot;net/sf/antcontrib/antcontrib.properties&quot; /&gt;
655 &lt;for ... /&gt;</code>
656 </li>
657 <li>declare a bundle of tasks using a <a href="CoreTypes/antlib.html">xml-file</a> holding these
658 taskname-ImplementationClass-pairs and <code>&lt;taskdef&gt;</code>
659 <br>
660 <code>&lt;taskdef resource=&quot;net/sf/antcontrib/antlib.xml&quot; /&gt;
661 &lt;for ... /&gt;</code>
662 </li>
663 <li>declare a bundle of tasks using a xml-file named antlib.xml, XML-namespace and
664 <a href="CoreTypes/antlib.html#antlibnamespace"><code>antlib:</code> protocoll handler</a>
665 <br>
666 <code>&lt;project xmlns:ac=&quot;antlib:net.sf.antconrib&quot;/&gt;
667 &lt;ac:for ... /&gt;</code>
668 </li>
669</ul>
670
671If you need a special function, you should
672<ol>
673 <li>have a look at this manual, because Ant provides lot of tasks</li>
674 <li>have a look at the external task page in the <a href="../external.html">manual</a>
675 (or better <a href="http://ant.apache.org/external.html">online</a>)</li>
676 <li>have a look at the external task <a href="http://wiki.apache.org/ant/AntExternalTaskdefs">wiki
677 page</a></li>
678 <li>ask on the <a href="http://ant.apache.org/mail.html#User%20List">Ant user</a> list</li>
679 <li><a href="tutorial-writing-tasks.html">implement </a>(and share) your own</li>
680</ol>
681
682</body>
683</html>
Note: See TracBrowser for help on using the repository browser.