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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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 Apache Ant</h1>
  23. <h2 id="buildfile">Writing a Simple Buildfile</h2>
  24. <p>Apache 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 id="projects">Projects</h3>
  31. <p>A <i>project</i> has three attributes:</p>
  32. <table>
  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, <em>since Ant 1.6.0</em>,
  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.<br/>
  61. A relative path is resolved relative to the directory containing
  62. the build file.
  63. </td>
  64. <td align="center" valign="top">No</td>
  65. </tr>
  66. </table>
  67. <p>Optionally, a description for the project can be provided as a
  68. top-level <code>&lt;description&gt;</code> element (see the <a
  69. href="Types/description.html">description</a> type).</p>
  70. <p>Each project defines one or more <i>targets</i>.
  71. A target is a set of <i>tasks</i> you want
  72. to be executed. When starting Ant, you can select which target(s) you
  73. want to have executed. When no target is given,
  74. the project's default is used.</p>
  75. <h3 id="targets">Targets</h3>
  76. <p>A target can depend on other targets. You might have a target for compiling,
  77. for example, and a target for creating a distributable. You can only build a
  78. distributable when you have compiled first, so the distribute target
  79. <i>depends on</i> the compile target. Ant resolves these dependencies.</p>
  80. <p>It should be noted, however, that Ant's <code>depends</code> attribute
  81. only specifies the <i>order</i> in which targets should be executed - it
  82. does not affect whether the target that specifies the dependency(s) gets
  83. executed if the dependent target(s) did not (need to) run.
  84. </p>
  85. <p>More information can be found in the
  86. dedicated <a href="targets.html">manual page</a>.</p>
  87. <h3 id="tasks">Tasks</h3>
  88. <p>A task is a piece of code that can be executed.</p>
  89. <p>A task can have multiple attributes (or arguments, if you prefer). The value
  90. of an attribute might contain references to a property. These references will be
  91. resolved before the task is executed.</p>
  92. <p>Tasks have a common structure:</p>
  93. <pre>&lt;<i>name</i> <i>attribute1</i>=&quot;<i>value1</i>&quot; <i>attribute2</i>=&quot;<i>value2</i>&quot; ... /&gt;</pre>
  94. <p>where <i>name</i> is the name of the task,
  95. <i>attributeN</i> is the attribute name, and
  96. <i>valueN</i> is the value for this attribute.</p>
  97. <p>There is a set of <a href="tasklist.html" target="navFrame">built-in tasks</a>, but it is also very
  98. easy to <a href="develop.html#writingowntask">write your own</a>.</p>
  99. <p>All tasks share a task name attribute. The value of
  100. this attribute will be used in the logging messages generated by
  101. Ant.</p>
  102. Tasks can be assigned an <code>id</code> attribute:
  103. <pre>&lt;<i>taskname</i> id="<i>taskID</i>" ... /&gt;</pre>
  104. where <i>taskname</i> is the name of the task, and <i>taskID</i> is
  105. a unique identifier for this task.
  106. You can refer to the
  107. corresponding task object in scripts or other tasks via this name.
  108. For example, in scripts you could do:
  109. <pre>
  110. &lt;script ... &gt;
  111. task1.setFoo("bar");
  112. &lt;/script&gt;
  113. </pre>
  114. to set the <code>foo</code> attribute of this particular task instance.
  115. In another task (written in Java), you can access the instance via
  116. <code>project.getReference("task1")</code>.
  117. <p>
  118. Note<sup>1</sup>: If &quot;task1&quot; has not been run yet, then
  119. it has not been configured (ie., no attributes have been set), and if it is
  120. going to be configured later, anything you've done to the instance may
  121. be overwritten.
  122. </p>
  123. <p>
  124. Note<sup>2</sup>: Future versions of Ant will most likely <i>not</i>
  125. be backward-compatible with this behaviour, since there will likely be no
  126. task instances at all, only proxies.
  127. </p>
  128. <h3 id="properties">Properties</h3>
  129. <p>Properties are an important way to customize a build process or
  130. to just provide shortcuts for strings that are used repeatedly
  131. inside a build file.</p>
  132. <p>In its most simple form properties are defined in the build file
  133. (for example by the <a href="Tasks/property.html">property</a>
  134. task) or might be set outside Ant. A property has a name and a
  135. value; the name is case-sensitive. Properties may be used in the
  136. value of task attributes or in the nested text of tasks that support
  137. them. This is done by placing the property name between
  138. &quot;<code>${</code>&quot; and &quot;<code>}</code>&quot; in the
  139. attribute value. For example, if there is a &quot;builddir&quot;
  140. property with the value &quot;build&quot;, then this could be used
  141. in an attribute like this: <code>${builddir}/classes</code>. This
  142. is resolved at run-time as <code>build/classes</code>.</p>
  143. <p>With Ant 1.8.0 property expansion has become much more powerful
  144. than simple key value pairs, more details can be
  145. found <a href="properties.html">in the concepts section</a> of this
  146. manual.</p>
  147. <h3 id="example">Example Buildfile</h3>
  148. <pre>
  149. &lt;project name=&quot;MyProject&quot; default=&quot;dist&quot; basedir=&quot;.&quot;&gt;
  150. &lt;description&gt;
  151. simple example build file
  152. &lt;/description&gt;
  153. &lt;!-- set global properties for this build --&gt;
  154. &lt;property name=&quot;src&quot; location=&quot;src&quot;/&gt;
  155. &lt;property name=&quot;build&quot; location=&quot;build&quot;/&gt;
  156. &lt;property name=&quot;dist&quot; location=&quot;dist&quot;/&gt;
  157. &lt;target name=&quot;init&quot;&gt;
  158. &lt;!-- Create the time stamp --&gt;
  159. &lt;tstamp/&gt;
  160. &lt;!-- Create the build directory structure used by compile --&gt;
  161. &lt;mkdir dir=&quot;${build}&quot;/&gt;
  162. &lt;/target&gt;
  163. &lt;target name=&quot;compile&quot; depends=&quot;init&quot;
  164. description=&quot;compile the source&quot;&gt;
  165. &lt;!-- Compile the java code from ${src} into ${build} --&gt;
  166. &lt;javac srcdir=&quot;${src}&quot; destdir=&quot;${build}&quot;/&gt;
  167. &lt;/target&gt;
  168. &lt;target name=&quot;dist&quot; depends=&quot;compile&quot;
  169. description=&quot;generate the distribution&quot;&gt;
  170. &lt;!-- Create the distribution directory --&gt;
  171. &lt;mkdir dir=&quot;${dist}/lib&quot;/&gt;
  172. &lt;!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --&gt;
  173. &lt;jar jarfile=&quot;${dist}/lib/MyProject-${DSTAMP}.jar&quot; basedir=&quot;${build}&quot;/&gt;
  174. &lt;/target&gt;
  175. &lt;target name=&quot;clean&quot;
  176. description=&quot;clean up&quot;&gt;
  177. &lt;!-- Delete the ${build} and ${dist} directory trees --&gt;
  178. &lt;delete dir=&quot;${build}&quot;/&gt;
  179. &lt;delete dir=&quot;${dist}&quot;/&gt;
  180. &lt;/target&gt;
  181. &lt;/project&gt;
  182. </pre>
  183. <p>Notice that we are declaring properties outside any target. <em>Since
  184. Ant 1.6</em>, all tasks can be declared outside targets (earlier version
  185. only allowed <tt>&lt;property&gt;</tt>,<tt>&lt;typedef&gt;</tt> and
  186. <tt>&lt;taskdef&gt;</tt>). When you do this they are evaluated before
  187. any targets are executed. Some tasks will generate build failures if
  188. they are used outside of targets as they may cause infinite loops
  189. otherwise (<code>&lt;antcall&gt;</code> for example).</p>
  190. <p>
  191. We have given some targets descriptions; this causes the <tt>projecthelp</tt>
  192. invocation option to list them as public targets with the descriptions; the
  193. other target is internal and not listed.
  194. <p>
  195. Finally, for this target to work the source in the <tt>src</tt> subdirectory
  196. should be stored in a directory tree which matches the package names. Check the
  197. <tt>&lt;javac&gt;</tt> task for details.
  198. <h3 id="filters">Token Filters</h3>
  199. <p>A project can have a set of tokens that might be automatically expanded if
  200. found when a file is copied, when the filtering-copy behavior is selected in the
  201. tasks that support this. These might be set in the buildfile
  202. by the <a href="Tasks/filter.html">filter</a> task.</p>
  203. <p>Since this can potentially be a very harmful behavior,
  204. the tokens in the files <b>must</b>
  205. be of the form <code>@</code><i>token</i><code>@</code>, where
  206. <i>token</i> is the token name that is set
  207. in the <code>&lt;filter&gt;</code> task. This token syntax matches the syntax of other build systems
  208. that perform such filtering and remains sufficiently orthogonal to most
  209. programming and scripting languages, as well as with documentation systems.</p>
  210. <p>Note: If a token with the format <code>@</code><i>token</i><code>@</code>
  211. is found in a file, but no
  212. filter is associated with that token, no changes take place;
  213. therefore, no escaping
  214. method is available - but as long as you choose appropriate names for your
  215. tokens, this should not cause problems.</p>
  216. <p><b>Warning:</b> If you copy binary files with filtering turned on, you can corrupt the
  217. files. This feature should be used with text files <em>only</em>.</p>
  218. <h3 id="path">Path-like Structures</h3>
  219. <p>You can specify <code>PATH</code>- and <code>CLASSPATH</code>-type
  220. references using both
  221. &quot;<code>:</code>&quot; and &quot;<code>;</code>&quot; as separator
  222. characters. Ant will
  223. convert the separator to the correct character of the current operating
  224. system.</p>
  225. <p>Wherever path-like values need to be specified, a nested element can
  226. be used. This takes the general form of:</p>
  227. <pre>
  228. &lt;classpath&gt;
  229. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  230. &lt;pathelement location=&quot;lib/helper.jar&quot;/&gt;
  231. &lt;/classpath&gt;
  232. </pre>
  233. <p>The <code>location</code> attribute specifies a single file or
  234. directory relative to the project's base directory (or an absolute
  235. filename), while the <code>path</code> attribute accepts colon-
  236. or semicolon-separated lists of locations. The <code>path</code>
  237. attribute is intended to be used with predefined paths - in any other
  238. case, multiple elements with <code>location</code> attributes should be
  239. preferred.</p>
  240. <p><em>Since Ant 1.8.2</em> the location attribute can also contain a
  241. wildcard in its last path component (i.e. it can end in a
  242. &quot;*&quot;) in order to support wildcard CLASSPATHs introduced
  243. with Java6. Ant will not expand or evaluate the wildcards and the
  244. resulting path may not work as anything else but a CLASSPATH - or
  245. even as a CLASSPATH for a Java VM prior to Java6.</p>
  246. <p>As a shortcut, the <code>&lt;classpath&gt;</code> tag
  247. supports <code>path</code> and
  248. <code>location</code> attributes of its own, so:</p>
  249. <pre>
  250. &lt;classpath&gt;
  251. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  252. &lt;/classpath&gt;
  253. </pre>
  254. <p>can be abbreviated to:</p>
  255. <pre>
  256. &lt;classpath path=&quot;${classpath}&quot;/&gt;
  257. </pre>
  258. <p>In addition, one or more
  259. <a href="Types/resources.html#collection">Resource Collection</a>s
  260. can be specified as nested elements (these must consist of
  261. <a href="Types/resources.html#file">file</a>-type resources only).
  262. Additionally, it should be noted that although resource collections are
  263. processed in the order encountered, certain resource collection types
  264. such as <a href="Types/fileset.html">fileset</a>,
  265. <a href="Types/dirset.html">dirset</a> and
  266. <a href="Types/resources.html#files">files</a>
  267. are undefined in terms of order.</p>
  268. <pre>
  269. &lt;classpath&gt;
  270. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  271. &lt;fileset dir=&quot;lib&quot;&gt;
  272. &lt;include name=&quot;**/*.jar&quot;/&gt;
  273. &lt;/fileset&gt;
  274. &lt;pathelement location=&quot;classes&quot;/&gt;
  275. &lt;dirset dir=&quot;${build.dir}&quot;&gt;
  276. &lt;include name=&quot;apps/**/classes&quot;/&gt;
  277. &lt;exclude name=&quot;apps/**/*Test*&quot;/&gt;
  278. &lt;/dirset&gt;
  279. &lt;filelist refid=&quot;third-party_jars&quot;/&gt;
  280. &lt;/classpath&gt;
  281. </pre>
  282. <p>This builds a path that holds the value of <code>${classpath}</code>,
  283. followed by all jar files in the <code>lib</code> directory,
  284. the <code>classes</code> directory, all directories named
  285. <code>classes</code> under the <code>apps</code> subdirectory of
  286. <code>${build.dir}</code>, except those
  287. that have the text <code>Test</code> in their name, and
  288. the files specified in the referenced FileList.</p>
  289. <p>If you want to use the same path-like structure for several tasks,
  290. you can define them with a <code>&lt;path&gt;</code> element at the
  291. same level as <i>target</i>s, and reference them via their
  292. <i>id</i> attribute--see <a href="#references">References</a> for an
  293. example.</p>
  294. <p>By default a path like structure will re-evaluate all nested
  295. resource collections whenever it is used, which may lead to
  296. unnecessary re-scanning of the filesystem. Since Ant 1.8.0 path has
  297. an optional <i>cache</i> attribute, if it is set to true, the path
  298. instance will only scan its nested resource collections once and
  299. assume it doesn't change during the build anymore (the default
  300. for <i>cache</i> still is <i>false</i>). Even if you are using the
  301. path only in a single task it may improve overall performance to set
  302. <i>cache</i> to <i>true</i> if you are using complex nested
  303. constructs.</p>
  304. <p>A path-like structure can include a reference to another path-like
  305. structure (a path being itself a resource collection)
  306. via nested <code>&lt;path&gt;</code> elements:</p>
  307. <pre>
  308. &lt;path id=&quot;base.path&quot;&gt;
  309. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  310. &lt;fileset dir=&quot;lib&quot;&gt;
  311. &lt;include name=&quot;**/*.jar&quot;/&gt;
  312. &lt;/fileset&gt;
  313. &lt;pathelement location=&quot;classes&quot;/&gt;
  314. &lt;/path&gt;
  315. &lt;path id=&quot;tests.path&quot; cache=&quot;true&quot;&gt;
  316. &lt;path refid=&quot;base.path&quot;/&gt;
  317. &lt;pathelement location=&quot;testclasses&quot;/&gt;
  318. &lt;/path&gt;
  319. </pre>
  320. The shortcuts previously mentioned for <code>&lt;classpath&gt;</code> are also valid for <code>&lt;path&gt;</code>.For example:
  321. <pre>
  322. &lt;path id=&quot;base.path&quot;&gt;
  323. &lt;pathelement path=&quot;${classpath}&quot;/&gt;
  324. &lt;/path&gt;
  325. </pre>
  326. can be written as:
  327. <pre>&lt;path id=&quot;base.path&quot; path=&quot;${classpath}&quot;/&gt;</pre>
  328. <h4 id="pathshortcut">Path Shortcut</h4>
  329. <p>
  330. In Ant 1.6 a shortcut for converting paths to OS specific strings
  331. in properties has been added. One can use the expression
  332. ${toString:<em>pathreference</em>} to convert a path element
  333. reference to a string that can be used for a path argument.
  334. For example:
  335. </p>
  336. <pre>
  337. &lt;path id="lib.path.ref"&gt;
  338. &lt;fileset dir="lib" includes="*.jar"/&gt;
  339. &lt;/path&gt;
  340. &lt;javac srcdir="src" destdir="classes"&gt;
  341. &lt;compilerarg arg="-Xbootclasspath/p:${toString:lib.path.ref}"/&gt;
  342. &lt;/javac&gt;
  343. </pre>
  344. <h3 id="arg">Command-line Arguments</h3>
  345. <p>Several tasks take arguments that will be passed to another
  346. process on the command line. To make it easier to specify arguments
  347. that contain space characters, nested <code>arg</code> elements can be used.</p>
  348. <table>
  349. <tr>
  350. <td valign="top"><b>Attribute</b></td>
  351. <td valign="top"><b>Description</b></td>
  352. <td valign="top"><b>Required</b></td>
  353. </tr>
  354. <tr>
  355. <td valign="top">value</td>
  356. <td valign="top">a single command-line argument; can contain space
  357. characters.</td>
  358. <td align="center" rowspan="5">Exactly one of these.</td>
  359. </tr>
  360. <tr>
  361. <td valign="top">file</td>
  362. <td valign="top">The name of a file as a single command-line
  363. argument; will be replaced with the absolute filename of the file.</td>
  364. </tr>
  365. <tr>
  366. <td valign="top">path</td>
  367. <td valign="top">A string that will be treated as a path-like
  368. string as a single command-line argument; you can use <code>;</code>
  369. or <code>:</code> as
  370. path separators and Ant will convert it to the platform's local
  371. conventions.</td>
  372. </tr>
  373. <tr>
  374. <td valign="top">pathref</td>
  375. <td valign="top"><a href="#references">Reference</a> to a path
  376. defined elsewhere. Ant will convert it to the platform's local
  377. conventions.</td>
  378. </tr>
  379. <tr>
  380. <td valign="top">line</td>
  381. <td valign="top">a space-delimited list of command-line arguments.</td>
  382. </tr>
  383. <tr>
  384. <td valign="top">prefix</td>
  385. <td valign="top">A fixed string to be placed in front of the
  386. argument. In the case of a line broken into parts, it will be
  387. placed in front of every part. <em>Since Ant 1.8.</em></td>
  388. <td valign="top" align="center">No</td>
  389. </tr>
  390. <tr>
  391. <td valign="top">suffix</td>
  392. <td valign="top">A fixed string to be placed immediately after the
  393. argument. In the case of a line broken into parts, it will be
  394. placed after every part. <em>Since Ant 1.8.</em></td>
  395. <td valign="top" align="center">No</td>
  396. </tr>
  397. </table>
  398. <p>It is highly recommended to avoid the <code>line</code> version
  399. when possible. Ant will try to split the command line in a way
  400. similar to what a (Unix) shell would do, but may create something that
  401. is very different from what you expect under some circumstances.</p>
  402. <h4>Examples</h4>
  403. <pre>
  404. &lt;arg value=&quot;-l -a&quot;/&gt;
  405. </pre>
  406. <p>is a single command-line argument containing a space character,
  407. <i>not</i> separate commands "-l" and "-a".</p>
  408. <pre>
  409. &lt;arg line=&quot;-l -a&quot;/&gt;
  410. </pre>
  411. <p>This is a command line with two separate arguments, "-l" and "-a".</p>
  412. <pre>
  413. &lt;arg path=&quot;/dir;/dir2:\dir3&quot;/&gt;
  414. </pre>
  415. <p>is a single command-line argument with the value
  416. <code>\dir;\dir2;\dir3</code> on DOS-based systems and
  417. <code>/dir:/dir2:/dir3</code> on Unix-like systems.</p>
  418. <h3 id="references">References</h3>
  419. <p>Any project element can be assigned an identifier using its
  420. <code>id</code> attribute. In most cases the element can subsequently
  421. be referenced by specifying the <code>refid</code> attribute on an
  422. element of the same type. This can be useful if you are going to
  423. replicate the same snippet of XML over and over again--using a
  424. <code>&lt;classpath&gt;</code> structure more than once, for example.</p>
  425. <p>The following example:</p>
  426. <pre>
  427. &lt;project ... &gt;
  428. &lt;target ... &gt;
  429. &lt;rmic ...&gt;
  430. &lt;classpath&gt;
  431. &lt;pathelement location=&quot;lib/&quot;/&gt;
  432. &lt;pathelement path=&quot;${java.class.path}/&quot;/&gt;
  433. &lt;pathelement path=&quot;${additional.path}&quot;/&gt;
  434. &lt;/classpath&gt;
  435. &lt;/rmic&gt;
  436. &lt;/target&gt;
  437. &lt;target ... &gt;
  438. &lt;javac ...&gt;
  439. &lt;classpath&gt;
  440. &lt;pathelement location=&quot;lib/&quot;/&gt;
  441. &lt;pathelement path=&quot;${java.class.path}/&quot;/&gt;
  442. &lt;pathelement path=&quot;${additional.path}&quot;/&gt;
  443. &lt;/classpath&gt;
  444. &lt;/javac&gt;
  445. &lt;/target&gt;
  446. &lt;/project&gt;
  447. </pre>
  448. <p>could be rewritten as:</p>
  449. <pre>
  450. &lt;project ... &gt;
  451. &lt;path id=&quot;project.class.path&quot;&gt;
  452. &lt;pathelement location=&quot;lib/&quot;/&gt;
  453. &lt;pathelement path=&quot;${java.class.path}/&quot;/&gt;
  454. &lt;pathelement path=&quot;${additional.path}&quot;/&gt;
  455. &lt;/path&gt;
  456. &lt;target ... &gt;
  457. &lt;rmic ...&gt;
  458. &lt;classpath refid=&quot;project.class.path&quot;/&gt;
  459. &lt;/rmic&gt;
  460. &lt;/target&gt;
  461. &lt;target ... &gt;
  462. &lt;javac ...&gt;
  463. &lt;classpath refid=&quot;project.class.path&quot;/&gt;
  464. &lt;/javac&gt;
  465. &lt;/target&gt;
  466. &lt;/project&gt;
  467. </pre>
  468. <p>All tasks that use nested elements for
  469. <a href="Types/patternset.html">PatternSet</a>s,
  470. <a href="Types/fileset.html">FileSet</a>s,
  471. <a href="Types/zipfileset.html">ZipFileSet</a>s or
  472. <a href="#path">path-like structures</a> accept references to these structures
  473. as shown in the examples. Using <code>refid</code> on a task will ordinarily
  474. have the same effect (referencing a task already declared), but the user
  475. should be aware that the interpretation of this attribute is dependent on the
  476. implementation of the element upon which it is specified. Some tasks (the
  477. <a href="Tasks/property.html">property</a> task is a handy example)
  478. deliberately assign a different meaning to <code>refid</code>.</p>
  479. <h3 id="external-tasks">Use of external tasks</h3>
  480. Ant supports a plugin mechanism for using third party tasks. For using them you
  481. have to do two steps:
  482. <ol>
  483. <li>place their implementation somewhere where Ant can find them</li>
  484. <li>declare them.</li>
  485. </ol>
  486. Don't add anything to the CLASSPATH environment variable - this is often the
  487. reason for very obscure errors. Use Ant's own <a href="install.html#optionalTasks">mechanisms</a>
  488. for adding libraries:
  489. <ul>
  490. <li>via command line argument <code>-lib</code></li>
  491. <li>adding to <code>${user.home}/.ant/lib</code></li>
  492. <li>adding to <code>${ant.home}/lib</code></li>
  493. </ul>
  494. For the declaration there are several ways:
  495. <ul>
  496. <li>declare a single task per using instruction using
  497. <code>&lt;<a href="Tasks/taskdef.html">taskdef</a> name=&quot;taskname&quot;
  498. classname=&quot;ImplementationClass&quot;/&gt;</code>
  499. <br>
  500. <code>&lt;taskdef name=&quot;for&quot; classname=&quot;net.sf.antcontrib.logic.For&quot; /&gt;
  501. &lt;for ... /&gt;</code>
  502. </li>
  503. <li>declare a bundle of tasks using a properties-file holding these
  504. taskname-ImplementationClass-pairs and <code>&lt;taskdef&gt;</code>
  505. <br>
  506. <code>&lt;taskdef resource=&quot;net/sf/antcontrib/antcontrib.properties&quot; /&gt;
  507. &lt;for ... /&gt;</code>
  508. </li>
  509. <li>declare a bundle of tasks using a <a href="Types/antlib.html">xml-file</a> holding these
  510. taskname-ImplementationClass-pairs and <code>&lt;taskdef&gt;</code>
  511. <br>
  512. <code>&lt;taskdef resource=&quot;net/sf/antcontrib/antlib.xml&quot; /&gt;
  513. &lt;for ... /&gt;</code>
  514. </li>
  515. <li>declare a bundle of tasks using a xml-file named antlib.xml, XML-namespace and
  516. <a href="Types/antlib.html#antlibnamespace"><code>antlib:</code> protocol handler</a>
  517. <br>
  518. <code>&lt;project xmlns:ac=&quot;antlib:net.sf.antcontrib&quot;/&gt;
  519. &lt;ac:for ... /&gt;</code>
  520. </li>
  521. </ul>
  522. If you need a special function, you should
  523. <ol>
  524. <li>have a look at this manual, because Ant provides lot of tasks</li>
  525. <li>have a look at the external task page <a href="http://ant.apache.org/external.html">online</a></li>
  526. <li>have a look at the external task <a href="http://wiki.apache.org/ant/AntExternalTaskdefs">wiki
  527. page</a></li>
  528. <li>ask on the <a href="http://ant.apache.org/mail.html#User%20List">Ant user</a> list</li>
  529. <li><a href="tutorial-writing-tasks.html">implement </a>(and share) your own</li>
  530. </ol>
  531. </body>
  532. </html>