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

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