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

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