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

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