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

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