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

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