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

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