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

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