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

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