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

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