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.

using.html 23 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Writing a Simple Buildfile</title>
  5. </head>
  6. <body>
  7. <h1>Using Ant</h1>
  8. <h2><a name="buildfile">Writing a Simple Buildfile</a></h2>
  9. <p>Ant's buildfiles are written in XML. Each buildfile contains one project
  10. and at least one (default) target. Targets contain task elements.
  11. Each task element of the buildfile can have an <code>id</code> attribute and
  12. can later be referred to by the value supplied to this. The value has
  13. to be unique. (For additional information, see the
  14. <a href="#tasks"> Tasks</a> section below.)</p>
  15. <h3><a name="projects">Projects</a></h3>
  16. <p>A <i>project</i> has three attributes:</p>
  17. <table border="1" cellpadding="2" cellspacing="0">
  18. <tr>
  19. <td valign="top"><b>Attribute</b></td>
  20. <td valign="top"><b>Description</b></td>
  21. <td align="center" valign="top"><b>Required</b></td>
  22. </tr>
  23. <tr>
  24. <td valign="top">name</td>
  25. <td valign="top">the name of the project.</td>
  26. <td align="center" valign="top">No</td>
  27. </tr>
  28. <tr>
  29. <td valign="top">default</td>
  30. <td valign="top">the default target to use when no target is supplied.</td>
  31. <td align="center" valign="top"><!-- No. No target will be run if omitted.--> Yes.</td>
  32. </tr>
  33. <tr>
  34. <td valign="top">basedir</td>
  35. <td valign="top">the base directory from which all path calculations are
  36. done. This attribute might be overridden by setting
  37. the &quot;basedir&quot;
  38. property beforehand. When this is done, it must be omitted in the
  39. project tag. If neither the attribute nor the property have
  40. been set, the parent directory of the buildfile will be used.</td>
  41. <td align="center" valign="top">No</td>
  42. </tr>
  43. </table>
  44. <p>Optionally, a description for the project can be provided as a
  45. top-level <code>&lt;description&gt;</code> element (see the <a
  46. href="CoreTypes/description.html">description</a> type).</p>
  47. <p>Each project defines one or more <i>targets</i>.
  48. A target is a set of <i>tasks</i> you want
  49. to be executed. When starting Ant, you can select which target(s) you
  50. want to have executed. When no target is given,
  51. the project's default is used.</p>
  52. <h3><a name="targets">Targets</a></h3>
  53. <p>A target can depend on other targets. You might have a target for compiling,
  54. for example, and a target for creating a distributable. You can only build a
  55. distributable when you have compiled first, so the distribute target
  56. <i>depends on</i> the compile target. Ant resolves these dependencies.</p>
  57. <p>It should be noted, however, that Ant's <code>depends</code> attribute
  58. only specifies the <i>order</i> in which targets should be executed - it
  59. does not affect whether the target that specifies the dependency(s) gets
  60. executed if the dependent target(s) did not (need to) run.
  61. </p>
  62. <p>Ant tries to execute the targets in the <code>depends</code>
  63. attribute in the order
  64. they appear (from left to right). Keep in mind that it is possible that a target
  65. can get executed earlier when an earlier target depends on it:</p>
  66. <blockquote>
  67. <pre>&lt;target name=&quot;A&quot;/&gt;
  68. &lt;target name=&quot;B&quot; depends=&quot;A&quot;/&gt;
  69. &lt;target name=&quot;C&quot; depends=&quot;B&quot;/&gt;
  70. &lt;target name=&quot;D&quot; depends=&quot;C,B,A&quot;/&gt;</pre>
  71. </blockquote>
  72. <p>Suppose we want to execute target D. From its
  73. <code>depends</code> attribute, you
  74. might think that first target C, then B and then A is executed.
  75. Wrong! C depends on B, and B depends on A, so first A is executed, then B, then C, and finally D.</p>
  76. <p>A target gets executed only once, even when more than one target
  77. depends on it (see the previous example).</p>
  78. <p>A target also has the ability to perform its execution if (or
  79. unless) a property has been set. This allows, for example, better
  80. control on the building process depending on the state of the system
  81. (java version, OS, command-line property defines, etc.). To make a target
  82. <i>sense</i> this property, you should add the <code>if</code> (or
  83. <code>unless</code>) attribute with the name of the property that the target
  84. should react to. <strong>Note:</strong> Ant will only check whether
  85. the property has been set, the value doesn't matter. A property set
  86. to the empty string is still an existing property. For example:</p>
  87. <blockquote>
  88. <pre>&lt;target name=&quot;build-module-A&quot; if=&quot;module-A-present&quot;/&gt;</pre>
  89. <pre>&lt;target name=&quot;build-own-fake-module-A&quot; unless=&quot;module-A-present&quot;/&gt;</pre>
  90. </blockquote>
  91. <p>In the first example, if the <code>module-A-present</code>
  92. property is set (to any value), the target will be run. In the second
  93. example, if the <code>module-A-present</code> property is set
  94. (again, to any value), the target will not be run.
  95. </p>
  96. <p>If no <code>if</code> and no <code>unless</code> attribute is present,
  97. the target will always be executed.</p>
  98. <p>The optional <code>description</code> attribute can be used to provide a one-line description of this target, which is printed by the
  99. <nobr><code>-projecthelp</code></nobr> command-line option. Targets
  100. without such a description are deemed internal and will not be listed,
  101. unless either the <nobr><code>-verbose</code></nobr> or
  102. <nobr><code>-debug</code></nobr> option is used.
  103. </p>
  104. <p>It is a good practice to place your <a
  105. href="CoreTasks/tstamp.html">tstamp</a> tasks in a so-called
  106. <i>initialization</i> target, on which
  107. all other targets depend. Make sure that target is always the first one in
  108. the depends list of the other targets. In this manual, most initialization targets
  109. have the name <code>&quot;init&quot;</code>.</p>
  110. <p>A target has the following attributes:</p>
  111. <table border="1" cellpadding="2" cellspacing="0">
  112. <tr>
  113. <td valign="top"><b>Attribute</b></td>
  114. <td valign="top"><b>Description</b></td>
  115. <td align="center" valign="top"><b>Required</b></td>
  116. </tr>
  117. <tr>
  118. <td valign="top">name</td>
  119. <td valign="top">the name of the target.</td>
  120. <td align="center" valign="top">Yes</td>
  121. </tr>
  122. <tr>
  123. <td valign="top">depends</td>
  124. <td valign="top">a comma-separated list of names of targets on which this
  125. target depends.</td>
  126. <td align="center" valign="top">No</td>
  127. </tr>
  128. <tr>
  129. <td valign="top">if</td>
  130. <td valign="top">the name of the property that must be set in order for this
  131. target to execute.</td>
  132. <td align="center" valign="top">No</td>
  133. </tr>
  134. <tr>
  135. <td valign="top">unless</td>
  136. <td valign="top">the name of the property that must not be set in order
  137. for this target to execute.</td>
  138. <td align="center" valign="top">No</td>
  139. </tr>
  140. <tr>
  141. <td valign="top">description</td>
  142. <td valign="top">a short description of this target's function.</td>
  143. <td align="center" valign="top">No</td>
  144. </tr>
  145. </table>
  146. </p>
  147. <p>A target name can be any alphanumeric string valid in the encoding of the XML
  148. file. The empty string &quot;&quot; is in this set, as is
  149. comma &quot;,&quot; and space &quot; &quot;.
  150. Please avoid using these, as they will not be supported in future Ant versions
  151. because of all the confusion they cause. IDE support of unusual target names,
  152. or any target name containing spaces, varies with the IDE.</p>
  153. <p>Targets beginning with a hyphen such as <code>&quot;-restart&quot;</code>
  154. are valid, and can be used
  155. to name targets that should not be called directly from the command line.</p>
  156. <h3><a name="tasks">Tasks</a></h3>
  157. <p>A task is a piece of code that can be executed.</p>
  158. <p>A task can have multiple attributes (or arguments, if you prefer). The value
  159. of an attribute might contain references to a property. These references will be
  160. resolved before the task is executed.</p>
  161. <p>Tasks have a common structure:</p>
  162. <blockquote>
  163. <pre>&lt;<i>name</i> <i>attribute1</i>=&quot;<i>value1</i>&quot; <i>attribute2</i>=&quot;<i>value2</i>&quot; ... /&gt;</pre>
  164. </blockquote>
  165. <p>where <i>name</i> is the name of the task,
  166. <i>attributeN</i> is the attribute name, and
  167. <i>valueN</i> is the value for this attribute.</p>
  168. <p>There is a set of <a href="coretasklist.html" target="navFrame">built-in tasks</a>, along with a
  169. number of
  170. <a href="optionaltasklist.html" target="navFrame"> optional tasks</a>, but it is also very
  171. easy to <a href="develop.html#writingowntask">write your own</a>.</p>
  172. <p>All tasks share a task name attribute. The value of
  173. this attribute will be used in the logging messages generated by
  174. Ant.</p>
  175. Tasks can be assigned an <code>id</code> attribute:
  176. <blockquote>
  177. <pre>&lt;<i>taskname</i> id="<i>taskID</i>" ... /&gt;</pre>
  178. </blockquote>
  179. where <i>taskname</i> is the name of the task, and <i>taskID</i> is
  180. a unique identifier for this task.
  181. You can refer to the
  182. corresponding task object in scripts or other tasks via this name.
  183. For example, in scripts you could do:
  184. <blockquote>
  185. <pre>
  186. &lt;script ... &gt;
  187. task1.setFoo("bar");
  188. &lt;/script&gt;
  189. </pre>
  190. </blockquote>
  191. to set the <code>foo</code> attribute of this particular task instance.
  192. In another task (written in Java), you can access the instance via
  193. <code>project.getReference("task1")</code>.
  194. <p>
  195. Note<sup>1</sup>: If &quot;task1&quot; has not been run yet, then
  196. it has not been configured (ie., no attributes have been set), and if it is
  197. going to be configured later, anything you've done to the instance may
  198. be overwritten.
  199. </p>
  200. <p>
  201. Note<sup>2</sup>: Future versions of Ant will most likely <i>not</i>
  202. be backward-compatible with this behaviour, since there will likely be no
  203. task instances at all, only proxies.
  204. </p>
  205. <h3><a name="properties">Properties</a></h3>
  206. <p>A project can have a set of properties. These might be set in the buildfile
  207. by the <a href="CoreTasks/property.html">property</a> task, or might be set outside Ant. A
  208. property has a name and a value; the name is case-sensitive. Properties may be used in the value of
  209. task attributes. This is done by placing the property name between
  210. &quot;<code>${</code>&quot; and &quot;<code>}</code>&quot; in the
  211. attribute value. For example,
  212. if there is a &quot;builddir&quot; property with the value
  213. &quot;build&quot;, then this could be used in an attribute like this:
  214. <code>${builddir}/classes</code>.
  215. This is resolved at run-time as <code>build/classes</code>.</p>
  216. <h3><a name="built-in-props">Built-in Properties</a></h3>
  217. <p>Ant provides access to all system properties as if they had been
  218. defined using a <code>&lt;property&gt;</code> task.
  219. For example, <code>${os.name}</code> expands to the
  220. name of the operating system.</p>
  221. <p>For a list of system properties see
  222. <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/System.html#getProperties()">the Javadoc of System.getProperties</a>.
  223. </p>
  224. <p>In addition, Ant has some built-in properties:</p>
  225. <pre>
  226. basedir the absolute path of the project's basedir (as set
  227. with the basedir attribute of &lt;project&gt;).
  228. ant.file the absolute path of the buildfile.
  229. ant.version the version of Ant
  230. ant.project.name the name of the project that is currently executing;
  231. it is set in the name attribute of &lt;project&gt;.
  232. ant.java.version the JVM version Ant detected; currently it can hold
  233. the values &quot;1.1&quot;, &quot;1.2&quot;, &quot;1.3&quot; and &quot;1.4&quot;.
  234. </pre>
  235. <a name="example"><h3>Example Buildfile</h3></a>
  236. <pre>
  237. &lt;project name=&quot;MyProject&quot; default=&quot;dist&quot; basedir=&quot;.&quot;&gt;
  238. &lt;description&gt;
  239. simple example build file
  240. &lt;/description&gt;
  241. &lt;!-- set global properties for this build --&gt;
  242. &lt;property name=&quot;src&quot; location=&quot;src&quot;/&gt;
  243. &lt;property name=&quot;build&quot; location=&quot;build&quot;/&gt;
  244. &lt;property name=&quot;dist&quot; location=&quot;dist&quot;/&gt;
  245. &lt;target name=&quot;init&quot;&gt;
  246. &lt;!-- Create the time stamp --&gt;
  247. &lt;tstamp/&gt;
  248. &lt;!-- Create the build directory structure used by compile --&gt;
  249. &lt;mkdir dir=&quot;${build}&quot;/&gt;
  250. &lt;/target&gt;
  251. &lt;target name=&quot;compile&quot; depends=&quot;init&quot;
  252. description=&quot;compile the source &quot; &gt;
  253. &lt;!-- Compile the java code from ${src} into ${build} --&gt;
  254. &lt;javac srcdir=&quot;${src}&quot; destdir=&quot;${build}&quot;/&gt;
  255. &lt;/target&gt;
  256. &lt;target name=&quot;dist&quot; depends=&quot;compile&quot;
  257. description=&quot;generate the distribution&quot; &gt;
  258. &lt;!-- Create the distribution directory --&gt;
  259. &lt;mkdir dir=&quot;${dist}/lib&quot;/&gt;
  260. &lt;!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --&gt;
  261. &lt;jar jarfile=&quot;${dist}/lib/MyProject-${DSTAMP}.jar&quot; basedir=&quot;${build}&quot;/&gt;
  262. &lt;/target&gt;
  263. &lt;target name=&quot;clean&quot;
  264. description=&quot;clean up&quot; &gt;
  265. &lt;!-- Delete the ${build} and ${dist} directory trees --&gt;
  266. &lt;delete dir=&quot;${build}&quot;/&gt;
  267. &lt;delete dir=&quot;${dist}&quot;/&gt;
  268. &lt;/target&gt;
  269. &lt;/project&gt;
  270. </pre>
  271. <p>Notice that we are declaring properties outside any target. As of
  272. Ant 1.6 all tasks can be declared outside targets (earlier version
  273. only allowed <tt>&lt;property&gt;</tt>,<tt>&lt;typedef&gt;</tt> and
  274. <tt>&lt;taskdef&gt;</tt>). When you do this they are evaluated before
  275. any targets are executed.</p>
  276. <p>
  277. We have given some targets descriptions; this causes the <tt>projecthelp</tt>
  278. invocation option to list them as public targets with the descriptions; the
  279. other target is internal and not listed.
  280. <p>
  281. Finally, for this target to work the source in the <tt>src</tt> subdirectory
  282. should be stored in a directory tree which matches the package names. Check the
  283. <tt>&lt;javac&gt;</tt> task for details.
  284. <a name="filters"><h3>Token Filters</h3></a>
  285. <p>A project can have a set of tokens that might be automatically expanded if
  286. found when a file is copied, when the filtering-copy behavior is selected in the
  287. tasks that support this. These might be set in the buildfile
  288. by the <a href="CoreTasks/filter.html">filter</a> task.</p>
  289. <p>Since this can potentially be a very harmful behavior,
  290. the tokens in the files <b>must</b>
  291. be of the form <code>@</code><i>token</i><code>@</code>, where
  292. <i>token</i> is the token name that is set
  293. in the <code>&lt;filter&gt;</code> task. This token syntax matches the syntax of other build systems
  294. that perform such filtering and remains sufficiently orthogonal to most
  295. programming and scripting languages, as well as with documentation systems.</p>
  296. <p>Note: If a token with the format <code>@</code><i>token</i><code>@</code>
  297. is found in a file, but no
  298. filter is associated with that token, no changes take place;
  299. therefore, no escaping
  300. method is available - but as long as you choose appropriate names for your
  301. tokens, this should not cause problems.</p>
  302. <p><b>Warning:</b> If you copy binary files with filtering turned on, you can corrupt the
  303. files. This feature should be used with text files <em>only</em>.</p>
  304. <h3><a name="path">Path-like Structures</a></h3>
  305. <p>You can specify <code>PATH</code>- and <code>CLASSPATH</code>-type
  306. references using both
  307. &quot;<code>:</code>&quot; and &quot;<code>;</code>&quot; as separator
  308. characters. Ant will
  309. convert the separator to the correct character of the current operating
  310. system.</p>
  311. <p>Wherever path-like values need to be specified, a nested element can
  312. be used. This takes the general form of:</p>
  313. <pre>
  314. &lt;classpath&gt;
  315. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  316. &lt;pathelement location=&quot;lib/helper.jar&quot;/&gt;
  317. &lt;/classpath&gt;
  318. </pre>
  319. <p>The <code>location</code> attribute specifies a single file or
  320. directory relative to the project's base directory (or an absolute
  321. filename), while the <code>path</code> attribute accepts colon-
  322. or semicolon-separated lists of locations. The <code>path</code>
  323. attribute is intended to be used with predefined paths - in any other
  324. case, multiple elements with <code>location</code> attributes should be
  325. preferred.</p>
  326. <p>As a shortcut, the <code>&lt;classpath&gt;</code> tag
  327. supports <code>path</code> and
  328. <code>location</code> attributes of its own, so:</p>
  329. <pre>
  330. &lt;classpath&gt;
  331. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  332. &lt;/classpath&gt;
  333. </pre>
  334. <p>can be abbreviated to:</p>
  335. <pre>
  336. &lt;classpath path=&quot;${classpath}&quot;/&gt;
  337. </pre>
  338. <p>In addition, <a href="CoreTypes/dirset.html">DirSet</a>s,
  339. <a href="CoreTypes/fileset.html">FileSet</a>s, and
  340. <a href="CoreTypes/filelist.html">FileList</a>s
  341. can be specified via nested <code>&lt;dirset&gt;</code>,
  342. <code>&lt;fileset&gt;</code>, and <code>&lt;filelist&gt;</code>
  343. elements, respectively. <em>Note</em>: The order in which the files
  344. building up a FileSet are added to the path-like structure is not
  345. defined.</p>
  346. <pre>
  347. &lt;classpath&gt;
  348. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  349. &lt;fileset dir=&quot;lib&quot;&gt;
  350. &lt;include name=&quot;**/*.jar&quot;/&gt;
  351. &lt;/fileset&gt;
  352. &lt;pathelement location=&quot;classes&quot;/&gt;
  353. &lt;dirset dir=&quot;${build.dir}&quot;&gt;
  354. &lt;include name=&quot;apps/**/classes&quot;/&gt;
  355. &lt;exclude name=&quot;apps/**/*Test*&quot;/&gt;
  356. &lt;/dirset&gt;
  357. &lt;filelist refid=&quot;third-party_jars&quot;&gt;
  358. &lt;/classpath&gt;
  359. </pre>
  360. <p>This builds a path that holds the value of <code>${classpath}</code>,
  361. followed by all jar files in the <code>lib</code> directory,
  362. the <code>classes</code> directory, all directories named
  363. <code>classes</code> under the <code>apps</code> subdirectory of
  364. <code>${build.dir}</code>, except those
  365. that have the text <code>Test</code> in their name, and
  366. the files specified in the referenced FileList.</p>
  367. <p>If you want to use the same path-like structure for several tasks,
  368. you can define them with a <code>&lt;path&gt;</code> element at the
  369. same level as <i>target</i>s, and reference them via their
  370. <i>id</i> attribute - see <a href="#references">References</a> for an
  371. example.</p>
  372. <p>A path-like structure can include a reference to another path-like
  373. structure via nested <code>&lt;path&gt;</code> elements:</p>
  374. <pre>
  375. &lt;path id=&quot;base.path&quot;&gt;
  376. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  377. &lt;fileset dir=&quot;lib&quot;&gt;
  378. &lt;include name=&quot;**/*.jar&quot;/&gt;
  379. &lt;/fileset&gt;
  380. &lt;pathelement location=&quot;classes&quot;/&gt;
  381. &lt;/path&gt;
  382. &lt;path id=&quot;tests.path&quot;&gt;
  383. &lt;path refid=&quot;base.path&quot;/&gt;
  384. &lt;pathelement location=&quot;testclasses&quot;/&gt;
  385. &lt;/path&gt;
  386. </pre>
  387. The shortcuts previously mentioned for <code>&lt;classpath&gt;</code> are also valid for <code>&lt;path&gt;</code>.For example:
  388. <pre>
  389. &lt;path id=&quot;base.path&quot;&gt;
  390. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  391. &lt;/path&gt;
  392. </pre>
  393. can be written as:
  394. <pre>
  395. &lt;path id=&quot;base.path&quot; path=&quot;${classpath}&quot;/&gt;
  396. </pre>
  397. <h3><a name="arg">Command-line Arguments</a></h3>
  398. <p>Several tasks take arguments that will be passed to another
  399. process on the command line. To make it easier to specify arguments
  400. that contain space characters, nested <code>arg</code> elements can be used.</p>
  401. <table border="1" cellpadding="2" cellspacing="0">
  402. <tr>
  403. <td width="12%" valign="top"><b>Attribute</b></td>
  404. <td width="78%" valign="top"><b>Description</b></td>
  405. <td width="10%" valign="top"><b>Required</b></td>
  406. </tr>
  407. <tr>
  408. <td valign="top">value</td>
  409. <td valign="top">a single command-line argument; can contain space
  410. characters.</td>
  411. <td align="center" rowspan="5">Exactly one of these.</td>
  412. </tr>
  413. <tr>
  414. <td valign="top">file</td>
  415. <td valign="top">The name of a file as a single command-line
  416. argument; will be replaced with the absolute filename of the file.</td>
  417. </tr>
  418. <tr>
  419. <td valign="top">path</td>
  420. <td valign="top">A string that will be treated as a path-like
  421. string as a single command-line argument; you can use <code>;</code>
  422. or <code>:</code> as
  423. path separators and Ant will convert it to the platform's local
  424. conventions.</td>
  425. </tr>
  426. <tr>
  427. <td valign="top">pathref</td>
  428. <td valign="top"><a href="#references">Reference</a> to a path
  429. defined elsewhere. Ant will convert it to the platform's local
  430. conventions.</td>
  431. </tr>
  432. <tr>
  433. <td valign="top">line</td>
  434. <td valign="top">a space-delimited list of command-line arguments.</td>
  435. </tr>
  436. </table>
  437. <p>It is highly recommended to avoid the <code>line</code> version
  438. when possible. Ant will try to split the command line in a way
  439. similar to what a (Unix) shell would do, but may create something that
  440. is very different from what you expect under some circumstances.</p>
  441. <h4>Examples</h4>
  442. <blockquote><pre>
  443. &lt;arg value=&quot;-l -a&quot;/&gt;
  444. </pre></blockquote>
  445. <p>is a single command-line argument containing a space character.</p>
  446. <blockquote><pre>
  447. &lt;arg line=&quot;-l -a&quot;/&gt;
  448. </pre></blockquote>
  449. <p>represents two separate command-line arguments.</p>
  450. <blockquote><pre>
  451. &lt;arg path=&quot;/dir;/dir2:\dir3&quot;/&gt;
  452. </pre></blockquote>
  453. <p>is a single command-line argument with the value
  454. <code>\dir;\dir2;\dir3</code> on DOS-based systems and
  455. <code>/dir:/dir2:/dir3</code> on Unix-like systems.</p>
  456. <h3><a name="references">References</a></h3>
  457. <p>The <code>id</code> attribute of the buildfile's elements can be
  458. used to refer to them. This can be useful if you are going to replicate
  459. the same snippet of XML over and over again - using a
  460. <code>&lt;classpath&gt;</code> structure more than once, for
  461. example.</p>
  462. <p>The following example:</p>
  463. <blockquote><pre>
  464. &lt;project ... &gt;
  465. &lt;target ... &gt;
  466. &lt;rmic ...&gt;
  467. &lt;classpath&gt;
  468. &lt;pathelement location=&quot;lib/&quot;/&gt;
  469. &lt;pathelement path=&quot;${java.class.path}/&quot;/&gt;
  470. &lt;pathelement path=&quot;${additional.path}&quot;/&gt;
  471. &lt;/classpath&gt;
  472. &lt;/rmic&gt;
  473. &lt;/target&gt;
  474. &lt;target ... &gt;
  475. &lt;javac ...&gt;
  476. &lt;classpath&gt;
  477. &lt;pathelement location=&quot;lib/&quot;/&gt;
  478. &lt;pathelement path=&quot;${java.class.path}/&quot;/&gt;
  479. &lt;pathelement path=&quot;${additional.path}&quot;/&gt;
  480. &lt;/classpath&gt;
  481. &lt;/javac&gt;
  482. &lt;/target&gt;
  483. &lt;/project&gt;
  484. </pre></blockquote>
  485. <p>could be rewritten as:</p>
  486. <blockquote><pre>
  487. &lt;project ... &gt;
  488. &lt;path id=&quot;project.class.path&quot;&gt;
  489. &lt;pathelement location=&quot;lib/&quot;/&gt;
  490. &lt;pathelement path=&quot;${java.class.path}/&quot;/&gt;
  491. &lt;pathelement path=&quot;${additional.path}&quot;/&gt;
  492. &lt;/path&gt;
  493. &lt;target ... &gt;
  494. &lt;rmic ...&gt;
  495. &lt;classpath refid=&quot;project.class.path&quot;/&gt;
  496. &lt;/rmic&gt;
  497. &lt;/target&gt;
  498. &lt;target ... &gt;
  499. &lt;javac ...&gt;
  500. &lt;classpath refid=&quot;project.class.path&quot;/&gt;
  501. &lt;/javac&gt;
  502. &lt;/target&gt;
  503. &lt;/project&gt;
  504. </pre></blockquote>
  505. <p>All tasks that use nested elements for <a
  506. href="CoreTypes/patternset.html">PatternSet</a>s, <a href="CoreTypes/fileset.html">FileSet</a>s,
  507. <a href="CoreTypes/zipfileset.html">ZipFileSet</a>s or
  508. <a href="#path">path-like structures</a> accept references to these
  509. structures as well.</p>
  510. <hr>
  511. <p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
  512. Reserved.</p>
  513. </body>
  514. </html>