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.

faq.xml 50 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. <?xml version="1.0"?>
  2. <!--
  3. Copyright 2001-2004 The Apache Software Foundation
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. -->
  14. <document>
  15. <properties>
  16. <author email="bodewig@apache.org">Stefan Bodewig</author>
  17. <title>Frequently Asked Questions</title>
  18. </properties>
  19. <faqsection title="About this FAQ">
  20. <faq id="latest-version">
  21. <question>Where do I find the latest version of this
  22. document?</question>
  23. <answer>
  24. <p>The latest version can always be found at Ant&apos;s homepage
  25. <a href="http://ant.apache.org/faq.html">http://ant.apache.org/faq.html</a>.</p>
  26. </answer>
  27. </faq>
  28. <faq id="adding-faqs">
  29. <question>How can I contribute to this FAQ?</question>
  30. <answer>
  31. <p>The page you are looking it is generated from
  32. <a href="http://cvs.apache.org/viewcvs.cgi/~checkout~/ant/xdocs/faq.xml">this</a>
  33. document. If you want to add a new question, please submit
  34. a patch against this document to one of Ant&apos;s mailing lists;
  35. hopefully, the structure is self-explanatory.</p>
  36. <p>If you don&apos;t know how to create a patch, see the patches
  37. section of <a href="http://jakarta.apache.org/site/source.html">this
  38. page</a>.</p>
  39. </answer>
  40. </faq>
  41. <faq id="creating-faq">
  42. <question>How do you create the HTML version of this
  43. FAQ?</question>
  44. <answer>
  45. <p>We use
  46. <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a>
  47. to render the HTML version from the original XML file.</p>
  48. <p>The Velocity stylesheets used to process the XML files can
  49. be found in the <code>xdocs/stylesheets</code> subdirectory of
  50. Ant&apos;s CVS repository - the build file
  51. <code>docs.xml</code> at the top level of the ant CVS
  52. module is used to drive Anakia.</p>
  53. <p>This file assumes that you have the
  54. <code>jakarta-site2</code> CVS module checked out as well, but
  55. if you follow the instruction from Anakia&apos;s homepage, you
  56. should get it to work without that. Just make sure all
  57. required jars are in the task&apos;s classpath.</p>
  58. </answer>
  59. </faq>
  60. </faqsection>
  61. <faqsection title="General">
  62. <faq id="what-is-ant">
  63. <question>What is Apache Ant?</question>
  64. <answer>
  65. <p> Ant is a Java-based build tool. In theory, it is kind of
  66. like Make, without Make&apos;s wrinkles and with the full
  67. portability of pure Java code.</p>
  68. </answer>
  69. </faq>
  70. <faq id="ant-name">
  71. <question>Why do you call it Ant?</question>
  72. <answer>
  73. <p>According to Ant&apos;s original author, James Duncan
  74. Davidson, the name is an acronym for &quot;Another Neat
  75. Tool&quot;.</p>
  76. <p>Later explanations go along the lines of &quot;ants
  77. do an extremely good job at building things&quot;, or
  78. &quot;ants are very small and can carry a weight dozens of times
  79. their own&quot; - describing what Ant is intended to
  80. be.</p>
  81. </answer>
  82. </faq>
  83. <faq id="history">
  84. <question>Tell us a little bit about Ant&apos;s history.</question>
  85. <answer>
  86. <p>Initially, Ant was part of the Tomcat code base, when it was
  87. donated to the Apache Software Foundation. It was
  88. created by James Duncan Davidson, who is also the original
  89. author of Tomcat. Ant was there to build Tomcat, nothing
  90. else.</p>
  91. <p>Soon thereafter, several open source Java projects realized
  92. that Ant could solve the problems they had with Makefiles.
  93. Starting with the projects hosted at Jakarta and the old Java
  94. Apache project, Ant spread like a virus and is now the build
  95. tool of choice for a lot of projects.</p>
  96. <p>In January 2000, Ant was moved to a separate CVS module and
  97. was promoted to a project of its own, independent of
  98. Tomcat, and became Apache Ant.</p>
  99. <p>The first version of Ant that was exposed to a larger audience
  100. was the one that shipped with Tomcat&apos;s 3.1 release on 19 April
  101. 2000. This version has later been referred to as Ant
  102. 0.3.1.</p>
  103. <p>The first official release of Ant as a stand-alone product was
  104. Ant 1.1, released on 19 July 2000. The complete release
  105. history:</p>
  106. <table>
  107. <tr>
  108. <th>Ant Version</th>
  109. <th>Release Date</th>
  110. </tr>
  111. <tr>
  112. <td>1.1</td>
  113. <td>19 July 2000</td>
  114. </tr>
  115. <tr>
  116. <td>1.2</td>
  117. <td>24 October 2000</td>
  118. </tr>
  119. <tr>
  120. <td>1.3</td>
  121. <td>3 March 2001</td>
  122. </tr>
  123. <tr>
  124. <td>1.4</td>
  125. <td>3 September 2001</td>
  126. </tr>
  127. <tr>
  128. <td>1.4.1</td>
  129. <td>11 October 2001</td>
  130. </tr>
  131. <tr>
  132. <td>1.5</td>
  133. <td>10 July 2002</td>
  134. </tr>
  135. <tr>
  136. <td>1.5.1</td>
  137. <td>3 October 2002</td>
  138. </tr>
  139. <tr>
  140. <td>1.5.2</td>
  141. <td>3 March 2003</td>
  142. </tr>
  143. <tr>
  144. <td>1.5.3</td>
  145. <td>9 April 2003</td>
  146. </tr>
  147. <tr>
  148. <td>1.5.4</td>
  149. <td>12 August 2003</td>
  150. </tr>
  151. <tr>
  152. <td>1.6.0</td>
  153. <td>18 December 2003</td>
  154. </tr>
  155. <tr>
  156. <td>1.6.1</td>
  157. <td>12 February 2004</td>
  158. </tr>
  159. </table>
  160. </answer>
  161. </faq>
  162. </faqsection>
  163. <faqsection title="Installation">
  164. <faq id="no-gnu-tar">
  165. <question>I get checksum errors when I try to extract the
  166. <code>tar.gz</code> distribution file. Why?</question>
  167. <answer>
  168. <p>Ant&apos;s distribution contains file names that are longer
  169. than 100 characters, which is not supported by the standard
  170. tar file format. Several different implementations of tar use
  171. different and incompatible ways to work around this
  172. restriction.</p>
  173. <p>Ant&apos;s &lt;tar&gt; task can create tar archives that use
  174. the GNU tar extension, and this has been used when putting
  175. together the distribution. If you are using a different
  176. version of tar (for example, the one shipping with Solaris),
  177. you cannot use it to extract the archive.</p>
  178. <p>The solution is to either install GNU tar, which can be
  179. found <a href="http://www.gnu.org/software/tar/tar.html">here</a>,
  180. or use the zip archive instead (you can extract it using
  181. <code>jar xf</code>).</p>
  182. </answer>
  183. </faq>
  184. </faqsection>
  185. <faqsection title="How do I ...">
  186. <faq id="adding-external-tasks">
  187. <question>How do I add an external task that I&apos;ve written to the
  188. page &quot;External Tools and Task&quot;?</question>
  189. <answer>
  190. <p>Join and post a message to the dev or user mailing
  191. list (one list is enough), including the following
  192. information:</p>
  193. <ul>
  194. <li>the name of the task/tool</li>
  195. <li>a short description of the task/tool</li>
  196. <li>a Compatibility: entry stating with which version(s) of
  197. Ant the tool/task is compatible to</li>
  198. <li>a URL: entry linking to the main page of the tool/task</li>
  199. <li>a Contact: entry containing the email address or the URL
  200. of a webpage for the person or list to contact for issues
  201. related to the tool/task. <strong>Note that we&apos;ll add a
  202. link on the page, so any email address added there is not
  203. obfuscated and can (and probably will) be abused by robots
  204. harvesting websites for addresses to spam.</strong></li>
  205. <li>a License: entry containing the type of license for the
  206. tool/task</li>
  207. </ul>
  208. <p>The preferred format for this information is a patch to <a
  209. href="http://cvs.apache.org/viewcvs.cgi/~checkout~/ant/xdocs/external.xml">this</a>
  210. document.</p>
  211. </answer>
  212. </faq>
  213. <faq id="passing-cli-args">
  214. <question>How do I pass parameters from the command line to my
  215. build file?</question>
  216. <answer>
  217. <p>Use properties. Using <code>ant
  218. -D<em>name</em>=<em>value</em></code> lets you define values for
  219. properties on the Ant command line. These properties can then be
  220. used within your build file as
  221. any normal property: <code>${<em>name</em>}</code> will put in
  222. <code><em>value</em></code>.</p>
  223. </answer>
  224. </faq>
  225. <faq id="jikes-switches">
  226. <question>How can I use Jikes-specific command-line
  227. switches?</question>
  228. <answer>
  229. <p>A couple of switches are supported via &quot;magic&quot;
  230. properties:</p>
  231. <table>
  232. <tr>
  233. <th>switch</th>
  234. <th>property</th>
  235. <th>default</th>
  236. </tr>
  237. <tr>
  238. <td>+E</td>
  239. <td>build.compiler.emacs</td>
  240. <td>false == not set</td>
  241. </tr>
  242. <tr>
  243. <td>+P</td>
  244. <td>build.compiler.pedantic</td>
  245. <td>false == not set</td>
  246. </tr>
  247. <tr>
  248. <td>+F</td>
  249. <td>build.compiler.fulldepend</td>
  250. <td>false == not set</td>
  251. </tr>
  252. <tr>
  253. <td><strong>(Only for Ant &lt; 1.4; replaced by the
  254. <code><strong>nowarn</strong></code>
  255. attribute of the <code><strong>&lt;javac&gt;</strong></code>
  256. task after that.)</strong><br></br>-nowarn</td>
  257. <td>build.compiler.warnings</td>
  258. <td>true == not set</td>
  259. </tr>
  260. </table>
  261. <p>With Ant &gt;= 1.5, you can also use nested
  262. <code>&lt;compilerarg&gt;</code> elements with the
  263. <code>&lt;javac&gt;</code> task.</p>
  264. </answer>
  265. </faq>
  266. <faq id="shell-redirect-1">
  267. <question>How do I include a &lt; character in my command-line arguments?</question>
  268. <answer>
  269. <p>The short answer is "Use: <code>&amp;lt;</code>".</p>
  270. <p>The long answer is that this probably won&apos;t do what you
  271. want anyway (see <a href="#shell-redirect-2">the next
  272. section</a>).</p>
  273. </answer>
  274. </faq>
  275. <faq id="shell-redirect-2">
  276. <question>How do I redirect standard input or standard output
  277. in the <code>&lt;exec&gt;</code> task?</question>
  278. <answer>
  279. <p>Say you want to redirect the standard output stream of the
  280. <code>m4</code> command to write to a file, something
  281. like:</p>
  282. <source><![CDATA[
  283. shell-prompt> m4 foo.m4 > foo
  284. ]]></source>
  285. <p>and try to translate it into</p>
  286. <source><![CDATA[
  287. <exec executable="m4">
  288. <arg value="foo.m4"/>
  289. <arg value="&gt;"/>
  290. <arg value="foo"/>
  291. </exec>
  292. ]]></source>
  293. <p>This will not do what you expect. The output redirection is
  294. performed by your shell, not the command itself, so this
  295. should read:</p>
  296. <source><![CDATA[
  297. <exec executable="/bin/sh">
  298. <arg value="-c" />
  299. <arg value="m4 foo.m4 &gt; foo" />
  300. </exec>
  301. ]]></source>
  302. <p>Note that you must use the <code>value</code> attribute of
  303. <code>&lt;arg&gt;</code> in the last element, in order to have
  304. the command passed as a single, quoted argument. Alternatively,
  305. you can use:</p>
  306. <source><![CDATA[
  307. <exec executable="/bin/sh">
  308. <arg line='-c "m4 foo.m4 &gt; foo"'/>
  309. </exec>
  310. ]]></source>
  311. <p>Note the double-quotes nested inside the single-quotes.</p>
  312. </answer>
  313. </faq>
  314. <faq id="batch-shell-execute">
  315. <question>How do I execute a batch file or shell script from Ant?</question>
  316. <answer>
  317. <p>On native Unix systems, you should be able to run shell scripts
  318. directly. On systems running a Unix-type shell (for example, Cygwin
  319. on Windows) execute the (command) shell instead - <code>cmd</code>
  320. for batch files, <code>sh</code> for shell scripts - then pass the
  321. batch file or shell script (plus any arguments to the script)
  322. as a single command, using the <code>/c</code> or
  323. <code>-c</code> switch, respectively. See
  324. <a href="#shell-redirect-2">the above section</a>
  325. for example <code>&lt;exec&gt;</code> tasks
  326. executing <code>sh</code>. For batch files, use something like:</p>
  327. <source><![CDATA[
  328. <exec dir="." executable="cmd" os="Windows NT">
  329. <arg line="/c test.bat"/>
  330. </exec>
  331. ]]></source>
  332. </answer>
  333. </faq>
  334. <faq id="multi-conditions">
  335. <question>I want to execute a particular target only if
  336. multiple conditions are true.</question>
  337. <answer>
  338. <p>There are actually several answers to this question.</p>
  339. <p>If you have only one set and one unset property to test,
  340. you can specify both an <code>if</code> and an <code>unless</code>
  341. attribute for the target, and they will act as if they
  342. are &quot;anded&quot; together.</p>
  343. <p>If you are using a version of Ant 1.3 or earlier, the
  344. way to work with all other cases is to chain targets together
  345. to determine the specific state you want to test for.</p>
  346. <p>To see how this works, assume you have three properties:
  347. <code>prop1</code>, <code>prop2</code>, and <code>prop3</code>.
  348. You want to test that <code>prop1</code> and <code>prop2</code>
  349. are set, and that <code>prop3</code> is not. If the condition
  350. holds true you want to echo &quot;yes&quot;.</p>
  351. <p>Here is the implementation in Ant 1.3 and earlier:</p>
  352. <source><![CDATA[
  353. <target name="cond" depends="cond-if"/>
  354. <target name="cond-if" if="prop1">
  355. <antcall target="cond-if-2"/>
  356. </target>
  357. <target name="cond-if-2" if="prop2">
  358. <antcall target="cond-if-3"/>
  359. </target>
  360. <target name="cond-if-3" unless="prop3">
  361. <echo message="yes"/>
  362. </target>
  363. ]]></source>
  364. <p>Note: <code>&lt;antcall&gt;</code> tasks do <em>not</em> pass
  365. property changes back up to the environment they were called
  366. from, so you would&apos;nt be able to, for example, set a
  367. <code>result</code> property in the <code>cond-if-3</code> target,
  368. then do
  369. <code>&lt;echo message=&quot;result is ${result}&quot;/&gt;</code>
  370. in the <code>cond</code> target.</p>
  371. <p>Starting with Ant 1.4, you can use the
  372. <code>&lt;condition&gt;</code> task.</p>
  373. <source><![CDATA[
  374. <target name="cond" depends="cond-if,cond-else"/>
  375. <target name="check-cond">
  376. <condition property="cond-is-true">
  377. <and>
  378. <not>
  379. <equals arg1="${prop1}" arg2="$${prop1}" />
  380. </not>
  381. <not>
  382. <equals arg1="${prop2}" arg2="$${prop2}" />
  383. </not>
  384. <equals arg1="${prop3}" arg2="$${prop3}" />
  385. </and>
  386. </condition>
  387. </target>
  388. <target name="cond-if" depends="check-cond" if="cond-is-true">
  389. <echo message="yes"/>
  390. </target>
  391. <target name="cond-else" depends="check-cond" unless="cond-is-true">
  392. <echo message="no"/>
  393. </target>
  394. ]]></source>
  395. <p>This version takes advantage of two things:</p>
  396. <ul>
  397. <li>If a property <code>a</code> has not been set,
  398. <code>${a}</code> will evaluate to <code>${a}</code>.</li>
  399. <li>To get a literal <code>$</code> in Ant, you have to
  400. escape it with another <code>$</code> - this will also break
  401. the special treatment of the <code>${</code> sequence.</li>
  402. </ul>
  403. <p>Because testing for a literal <code>${property}</code> string
  404. isn&apos;t all that readable or easy to understand,
  405. post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element
  406. to the <code>&lt;condition&gt;</code> task.</p>
  407. <p>Here is the previous example done using
  408. <code>&lt;isset&gt;</code>:</p>
  409. <source><![CDATA[
  410. <target name="check-cond">
  411. <condition property="cond-is-true">
  412. <and>
  413. <isset property="prop1"/>
  414. <isset property="prop2"/>
  415. <not>
  416. <isset property="prop3"/>
  417. </not>
  418. </and>
  419. </condition>
  420. </target>
  421. ]]></source>
  422. <p>The last option is to use a scripting language to set the
  423. properties. This can be particularly handy when you need much
  424. finer control than the simple conditions shown here but, of
  425. course, comes with the overhead of adding JAR files to support
  426. the language, to say nothing of the added maintenance in requiring
  427. two languages to implement a single system. See the
  428. <a href="manual/OptionalTasks/script.html">
  429. <code>&lt;script&gt;</code> task documentation</a> for more
  430. details.</p>
  431. </answer>
  432. </faq>
  433. <faq id="encoding">
  434. <question>How can I include national characters like German
  435. umlauts in my build file?</question>
  436. <answer>
  437. <p>You need to tell the XML parser which character encoding
  438. your build file uses, this is done inside the <a
  439. href="http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd">XML
  440. declaration</a>.</p>
  441. <p>By default the parser assumes you are using the UTF-8
  442. encoding instead of your platform&apos;s default. For most Western
  443. European countries you should set the encoding to
  444. <code>ISO-8859-1</code>. To do so, make the very first line
  445. of you build file read like</p>
  446. <source><![CDATA[
  447. <?xml version="1.0" encoding="ISO-8859-1" ?>
  448. ]]></source>
  449. </answer>
  450. </faq>
  451. <faq id="use-zip-instead-of-jar">
  452. <question>How do I use <code>jar</code>&apos;s <code>M</code> switch?
  453. I don&apos;t want a MANIFEST.</question>
  454. <answer>
  455. <p>A JAR archive is a ZIP file, so if you don&apos;t want a
  456. MANIFEST you can simply use <code>&lt;zip&gt;</code>.</p>
  457. <p>If your file names contain national characters you should
  458. know that Sun&apos;s <code>jar</code> utility like Ant&apos;s
  459. <code>&lt;jar&gt;</code> uses UFT8 to encode their names while
  460. <code>&lt;zip&gt;</code> uses your platforms default encoding.
  461. Use the encoding attribute of <code>&lt;zip&gt;</code> if
  462. necessary.</p>
  463. </answer>
  464. </faq>
  465. <faq id="propertyvalue-as-name-for-property">
  466. <question>How can I do something like <code>&lt;property name="prop"
  467. value="${${anotherprop}}"/&gt;</code> (double expanding the property)?</question>
  468. <answer>
  469. <p>Without any external help you can not.</p>
  470. <p>With &lt;script/&gt;, which needs external libraries, you can do</p>
  471. <source><![CDATA[
  472. <script language="javascript">
  473. propname = project.getProperty("anotherprop");
  474. project.setNewProperty("prop", propname);
  475. </script>
  476. ]]></source>
  477. <p>With AntContrib (external task library) you can do <code>
  478. &lt;propertycopy name="prop" from="${anotherprop}"/&gt;</code>.</p>
  479. </answer>
  480. </faq>
  481. </faqsection>
  482. <faqsection title="It doesn&apos;t work (as expected)">
  483. <faq id="always-recompiles">
  484. <question>Why does Ant always recompile all my Java files?</question>
  485. <answer>
  486. <p>In order to find out which files should be compiled, Ant
  487. compares the timestamps of the source files to those of the
  488. resulting <code>.class</code> files. Opening all source files
  489. to find out which package they belong to would be very
  490. inefficient. Instead, Ant expects you to place your
  491. source files in a directory hierarchy that mirrors your
  492. package hierarchy and to point Ant to the root of this
  493. directory tree with the <code>srcdir</code> attribute.</p>
  494. <p>Say you have <code>&lt;javac srcdir=&quot;src&quot;
  495. destdir=&quot;dest&quot;/&gt;</code>. If Ant finds a file
  496. <code>src/a/b/C.java</code>, it expects it to be in package
  497. <code>a.b</code> so that the resulting <code>.class</code>
  498. file is going to be <code>dest/a/b/C.class</code>.</p>
  499. <p>If your source-tree directory structure does not match your
  500. package structure, Ant&apos;s heuristic won&apos;t work, and
  501. it will recompile classes that are up-to-date. Ant is not the
  502. only tool that expects a source-tree layout like this.</p>
  503. <p>If you have Java source files that aren&apos;t declared to
  504. be part of any package, you can still use the <code>&lt;javac&gt;</code>
  505. task to compile these files correctly - just set the
  506. <code>srcdir</code> and <code>destdir</code> attributes to
  507. the actual directory the source
  508. files live in and the directory the class files should go into,
  509. respectively.</p>
  510. </answer>
  511. </faq>
  512. <faq id="defaultexcludes">
  513. <question>I&apos;ve used a <code>&lt;delete&gt;</code> task to
  514. delete unwanted SourceSafe control files (CVS files, editor
  515. backup files, etc.), but it doesn&apos;t seem to work; the files
  516. never get deleted. What&apos;s wrong?</question>
  517. <answer>
  518. <p>This is probably happening because, by default, Ant excludes
  519. SourceSafe control files (<code>vssver.scc</code>) and certain other
  520. files from FileSets.</p>
  521. <p>Here&apos;s what you probably did:</p>
  522. <source><![CDATA[
  523. <delete>
  524. <fileset dir="${build.src}" includes="**/vssver.scc"/>
  525. </delete>
  526. ]]></source>
  527. <p>You need to switch off the default exclusions,
  528. and it will work:</p>
  529. <source><![CDATA[
  530. <delete>
  531. <fileset dir="${build.src}" includes="**/vssver.scc"
  532. defaultexcludes="no"/>
  533. </delete>
  534. ]]></source>
  535. <p>For a complete listing of the patterns that are excluded
  536. by default, see <a href="manual/dirtasks.html#defaultexcludes">the user
  537. manual</a>.</p>
  538. </answer>
  539. </faq>
  540. <faq id="stop-dependency">
  541. <question>I have a target I want to skip if a property is set,
  542. so I have <code>unless=&quot;property&quot;</code> as an attribute
  543. of the target, but all the targets this target
  544. depends on are still executed. Why?</question>
  545. <answer>
  546. <p>The list of dependencies is generated by Ant before any of the
  547. targets are run. This allows dependent targets, such as an
  548. <code>init</code> target, to set properties that can control the
  549. execution of the targets higher in the dependency graph. This
  550. is a good thing.</p>
  551. <p>However, when your dependencies break down the
  552. higher-level task
  553. into several smaller steps, this behaviour becomes
  554. counter-intuitive. There are a couple of solutions available:
  555. </p>
  556. <ol>
  557. <li>Put the same condition on each of the dependent targets.</li>
  558. <li>Execute the steps using <code>&lt;antcall&gt;</code>,
  559. instead of specifying them inside the <code>depends</code>
  560. attribute.</li>
  561. </ol>
  562. </answer>
  563. </faq>
  564. <faq id="include-order">
  565. <question>In my <code>&lt;fileset&gt;</code>, I&apos;ve put in an
  566. <code>&lt;exclude&gt;</code> of all files followed by an
  567. <code>&lt;include&gt;</code> of just the files I want, but it
  568. isn&apos;t giving me any files at all. What&apos;s wrong?
  569. </question>
  570. <answer>
  571. <p>The order of the <code>&lt;include&gt;</code> and
  572. <code>&lt;exclude&gt;</code> tags within a <code>&lt;fileset&gt;</code>
  573. is ignored when the FileSet is created. Instead, all of the
  574. <code>&lt;include&gt;</code> elements are processed together,
  575. followed by all of the <code>&lt;exclude&gt;</code>
  576. elements. This means that the <code>&lt;exclude&gt;</code>
  577. elements only apply to the file list produced by the
  578. <code>&lt;include&gt;</code> elements.</p>
  579. <p>To get the files you want, focus on just the
  580. <code>&lt;include&gt;</code> patterns that would be necessary
  581. to get them. If you find you need to trim the list that the
  582. <code>&lt;include&gt;</code> elements produce, then use
  583. <code>&lt;exclude&gt;</code> elements.</p>
  584. </answer>
  585. </faq>
  586. <faq id="properties-not-trimmed">
  587. <question><code>ant</code> failed to build my program via javac
  588. even when I put the needed jars in an external
  589. <code>build.properties</code> file and reference them by
  590. <code>pathelement</code> or <code>classpath refid</code>.</question>
  591. <answer>
  592. <p>When <code>ant</code> loads properties from an external
  593. file it dosn&apos;t touch the value of properties, trailing blanks
  594. will not be trimmed for example.</p>
  595. <p>If the value represents a file path, like a jar needed to
  596. compile, the task which requires the value, javac for example
  597. would fail to compile since it can&apos;t find the file due to
  598. trailing spaces.</p>
  599. </answer>
  600. </faq>
  601. <faq id="winzip-lies">
  602. <question>Ant creates WAR files with a lower-case
  603. <code>web-inf</code> or JAR files with a lower-case
  604. <code>meta-inf</code> directory.</question>
  605. <answer>
  606. <p>No it doesn&apos;t.</p>
  607. <p>You may have seen these lower-case directory names in
  608. WinZIP, but WinZIP is trying to be helpful (and fails). If
  609. WinZIP encounters a filename that is all upper-case, it
  610. assumes it has come from an old DOS box and changes the case to
  611. all lower-case for you.</p>
  612. <p>If you extract (or just check) the archive with jar, you
  613. will see that the names have the correct case.</p>
  614. <p>With WinZIP (version 8.1 at least), this can be corrected in the
  615. configuration. In the Options/Configuration menu, in the View tab, General
  616. section, check the "Allow all upper case files names" box. The META-INF and
  617. WEB-INF will look correct.</p>
  618. </answer>
  619. </faq>
  620. </faqsection>
  621. <faqsection title="Ant and IDEs/Editors">
  622. <faq id="integration">
  623. <question>Is Ant supported by my IDE/Editor?</question>
  624. <answer>
  625. <p>See the <a href="external.html#IDE and Editor Integration">section
  626. on IDE integration</a> on our External Tools and Tasks page.</p>
  627. </answer>
  628. </faq>
  629. <faq id="emacs-mode">
  630. <question>Why doesn&apos;t (X)Emacs/vi/MacOS X&apos;s project builder
  631. correctly parse the error messages generated by Ant?</question>
  632. <answer>
  633. <p>Ant adds a &quot;banner&quot; with the name of the current
  634. task in front of all logging messages - and there are no built-in
  635. regular expressions in your editor that would account for
  636. this.</p>
  637. <p>You can disable this banner by invoking Ant with the
  638. <code>-emacs</code> switch. To make Ant autodetect
  639. Emacs&apos; compile mode, put this into your
  640. <code>.antrc</code> (contributed by Ville Skytt&#228;).</p>
  641. <source><![CDATA[
  642. # Detect (X)Emacs compile mode
  643. if [ "$EMACS" = "t" ] ; then
  644. ANT_ARGS="$ANT_ARGS -emacs"
  645. ANT_OPTS="$ANT_OPTS -Dbuild.compiler.emacs=true"
  646. fi
  647. ]]></source>
  648. <p>Alternatively, you can add the following snippet to your
  649. <code>.emacs</code> to make Emacs understand Ant&apos;s
  650. output.</p>
  651. <source><![CDATA[
  652. (require 'compile)
  653. (setq compilation-error-regexp-alist
  654. (append (list
  655. ;; works for jikes
  656. '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3)
  657. ;; works for javac
  658. '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2))
  659. compilation-error-regexp-alist))
  660. ]]></source>
  661. <p>Yet another alternative that preserves most of Ant&apos;s
  662. formatting is to pipe Ant&apos;s output through the following Perl
  663. script by Dirk-Willem van Gulik:</p>
  664. <source><![CDATA[
  665. #!/usr/bin/perl
  666. #
  667. # May 2001 dirkx@apache.org - remove any
  668. # [foo] lines from the output; keeping
  669. # spacing more or less there.
  670. #
  671. $|=1;
  672. while(<STDIN>) {
  673. if (s/^(\s+)\[(\w+)\]//) {
  674. if ($2 ne $last) {
  675. print "$1\[$2\]";
  676. $s = ' ' x length($2);
  677. } else {
  678. print "$1 $s ";
  679. };
  680. $last = $2;
  681. };
  682. print;
  683. };
  684. ]]></source>
  685. </answer>
  686. </faq>
  687. </faqsection>
  688. <faqsection title="Advanced Issues">
  689. <faq id="dtd">
  690. <question>Is there a DTD that I can use to validate my build
  691. files?</question>
  692. <answer>
  693. <p>An incomplete DTD can be created by the
  694. <code>&lt;antstructure&gt;</code> task - but this one
  695. has a few problems:</p>
  696. <ul>
  697. <li>It doesn&apos;t know about required attributes. Only
  698. manual tweaking of this file can help here.</li>
  699. <li>It is not complete - if you add new tasks via
  700. <code>&lt;taskdef&gt;</code> it won&apos;t know about it. See
  701. <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this
  702. page</a> by Michel Casabianca for a solution to this
  703. problem. Note that the DTD you can download at this page
  704. is based on Ant 0.3.1.</li>
  705. <li>It may even be an invalid DTD. As Ant allows tasks
  706. writers to define arbitrary elements, name collisions will
  707. happen quite frequently - if your version of Ant contains
  708. the optional <code>&lt;test&gt;</code> and
  709. <code>&lt;junit&gt;</code> tasks, there are two XML
  710. elements named <code>test</code> (the task and the nested child
  711. element of <code>&lt;junit&gt;</code>) with different attribute
  712. lists. This problem cannot be solved; DTDs don&apos;t give a
  713. syntax rich enough to support this.</li>
  714. </ul>
  715. </answer>
  716. </faq>
  717. <faq id="xml-entity-include">
  718. <question>How do I include an XML snippet in my build file?</question>
  719. <answer>
  720. <p>You can use XML&apos;s way of including external files and let
  721. the parser do the job for Ant:</p>
  722. <source><![CDATA[
  723. <?xml version="1.0"?>
  724. <!DOCTYPE project [
  725. <!ENTITY common SYSTEM "file:./common.xml">
  726. ]>
  727. <project name="test" default="test" basedir=".">
  728. <target name="setup">
  729. ...
  730. </target>
  731. &common;
  732. ...
  733. </project>
  734. ]]></source>
  735. <p>will literally include the contents of <code>common.xml</code> where
  736. you&apos;ve placed the <code>&amp;common;</code> entity.</p>
  737. <p>In combination with a DTD, this would look like this:</p>
  738. <source><![CDATA[
  739. <!DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "file:./ant.dtd" [
  740. <!ENTITY include SYSTEM "file:./header.xml">
  741. ]>
  742. ]]></source>
  743. <p>Starting with Ant 1.6, there is a new
  744. <code>&lt;import&gt;</code> task that can (also) be used to
  745. include build file fragments. Unlike the snippets used with
  746. entity includes, the referenced files have to be complete Ant
  747. build files, though.</p>
  748. <p>The example above would become:</p>
  749. <source><![CDATA[
  750. <?xml version="1.0"?>
  751. <project name="test" default="test" basedir=".">
  752. <target name="setup">
  753. ...
  754. </target>
  755. <import file="./common.xml"/>
  756. ...
  757. </project>
  758. ]]></source>
  759. <p>Unlike entity includes, <code>&lt;import&gt;</code> will
  760. let you use Ant properties in the file name.</p>
  761. </answer>
  762. </faq>
  763. <faq id="mail-logger">
  764. <question>How do I send an email with the result of my build
  765. process?</question>
  766. <answer>
  767. <p>If you are using a nightly build of Ant 1.5 after
  768. 2001-12-14, you can use the built-in MailLogger:</p>
  769. <source><![CDATA[
  770. ant -logger org.apache.tools.ant.listener.MailLogger
  771. ]]></source>
  772. <p>See the <a href="http://cvs.apache.org/viewcvs/~checkout~/ant/docs/manual/listeners.html?content-type=text/html">Listeners
  773. &amp; Loggers</a> documentation for details on the properties
  774. required.</p>
  775. <p>For older versions of Ant, you can use a custom
  776. BuildListener that sends out an email
  777. in the buildFinished() method. Will Glozer
  778. &lt;will.glozer@jda.com&gt; has written such a listener based
  779. on <a href="http://java.sun.com/products/javamail/">JavaMail</a>.
  780. The source is:</p>
  781. <source><![CDATA[
  782. import java.io.*;
  783. import java.util.*;
  784. import javax.mail.*;
  785. import javax.mail.internet.*;
  786. import org.apache.tools.ant.*;
  787. /**
  788. * A simple listener that waits for a build to finish and sends an email
  789. * of the results. The settings are stored in "monitor.properties" and
  790. * are fairly self explanatory.
  791. *
  792. * @author Will Glozer
  793. * @version 1.05a 09/06/2000
  794. */
  795. public class BuildMonitor implements BuildListener {
  796. protected Properties props;
  797. /**
  798. * Create a new BuildMonitor.
  799. */
  800. public BuildMonitor() throws Exception {
  801. props = new Properties();
  802. InputStream is = getClass().getResourceAsStream("monitor.properties");
  803. props.load(is);
  804. is.close();
  805. }
  806. public void buildStarted(BuildEvent e) {
  807. }
  808. /**
  809. * Determine the status of the build and the actions to follow, now that
  810. * the build has completed.
  811. *
  812. * @param e Event describing the build status.
  813. */
  814. public void buildFinished(BuildEvent e) {
  815. Throwable th = e.getException();
  816. String status = (th != null) ? "failed" : "succeeded";
  817. try {
  818. String key = "build." + status;
  819. if (props.getProperty(key + ".notify").equalsIgnoreCase("false")) {
  820. return;
  821. }
  822. Session session = Session.getDefaultInstance(props, null);
  823. MimeMessage message = new MimeMessage(session);
  824. message.addRecipients(Message.RecipientType.TO, parseAddresses(
  825. props.getProperty(key + ".email.to")));
  826. message.setSubject(props.getProperty(key + ".email.subject"));
  827. BufferedReader br = new BufferedReader(new FileReader(
  828. props.getProperty("build.log")));
  829. StringWriter sw = new StringWriter();
  830. String line = br.readLine();
  831. while (line != null) {
  832. sw.write(line);
  833. sw.write("\n");
  834. line = br.readLine();
  835. }
  836. br.close();
  837. message.setText(sw.toString(), "UTF-8");
  838. sw.close();
  839. Transport transport = session.getTransport();
  840. transport.connect();
  841. transport.send(message);
  842. transport.close();
  843. } catch (Exception ex) {
  844. System.out.println("BuildMonitor failed to send email!");
  845. ex.printStackTrace();
  846. }
  847. }
  848. /**
  849. * Parse a comma separated list of internet email addresses.
  850. *
  851. * @param s The list of addresses.
  852. * @return Array of Addresses.
  853. */
  854. protected Address[] parseAddresses(String s) throws Exception {
  855. StringTokenizer st = new StringTokenizer(s, ",");
  856. Address[] addrs = new Address[st.countTokens()];
  857. for (int i = 0; i < addrs.length; i++) {
  858. addrs[i] = new InternetAddress(st.nextToken());
  859. }
  860. return addrs;
  861. }
  862. public void messageLogged(BuildEvent e) {
  863. }
  864. public void targetStarted(BuildEvent e) {
  865. }
  866. public void targetFinished(BuildEvent e) {
  867. }
  868. public void taskStarted(BuildEvent e) {
  869. }
  870. public void taskFinished(BuildEvent e) {
  871. }
  872. }
  873. ]]></source>
  874. <p>With a <code>monitor.properties</code> like this:</p>
  875. <source><![CDATA[
  876. # configuration for build monitor
  877. mail.transport.protocol=smtp
  878. mail.smtp.host=<host>
  879. mail.from=Will Glozer <will.glozer@jda.com>
  880. build.log=build.log
  881. build.failed.notify=true
  882. build.failed.email.to=will.glozer@jda.com
  883. build.failed.email.subject=Nightly build failed!
  884. build.succeeded.notify=true
  885. build.succeeded.email.to=will.glozer@jda.com
  886. build.succeeded.email.subject=Nightly build succeeded!
  887. ]]></source>
  888. <p><code>monitor.properties</code> should be placed right next
  889. to your compiled <code>BuildMonitor.class</code>. To use it,
  890. invoke Ant like:</p>
  891. <source><![CDATA[
  892. ant -listener BuildMonitor -logfile build.log
  893. ]]></source>
  894. <p>Make sure that <code>mail.jar</code> from JavaMail and
  895. <code>activation.jar</code> from the
  896. <a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java
  897. Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p>
  898. </answer>
  899. </faq>
  900. <faq id="listener-properties">
  901. <question>How do I get at the properties that Ant was running
  902. with from inside BuildListener?</question>
  903. <answer>
  904. <p>You can get at a hashtable with all the properties that Ant
  905. has been using through the BuildEvent parameter. For
  906. example:</p>
  907. <source><![CDATA[
  908. public void buildFinished(BuildEvent e) {
  909. Hashtable table = e.getProject().getProperties();
  910. String buildpath = (String)table.get("build.path");
  911. ...
  912. }
  913. ]]></source>
  914. <p>This is more accurate than just reading the same property
  915. files that your project does, since it will give the correct
  916. results for properties that were specified on the Ant command line.</p>
  917. </answer>
  918. </faq>
  919. </faqsection>
  920. <faqsection title="Known Problems">
  921. <faq id="remove-cr">
  922. <question>&lt;chmod&gt; or &lt;exec&gt; doesn&apos;t work in Ant
  923. 1.3 on Unix</question>
  924. <answer>
  925. <p>The <code>antRun</code> script in <code>ANT_HOME/bin</code>
  926. has DOS instead of Unix line endings; you must remove the
  927. carriage-return characters from this file. This can be done by
  928. using Ant&apos;s <code>&lt;fixcrlf&gt;</code> task
  929. or something like:</p>
  930. <source><![CDATA[
  931. tr -d '\r' < $ANT_HOME/bin/antRun > /tmp/foo
  932. mv /tmp/foo $ANT_HOME/bin/antRun
  933. ]]></source>
  934. </answer>
  935. </faq>
  936. <faq id="javadoc-cannot-execute">
  937. <question>JavaDoc failed: java.io.IOException: javadoc: cannot execute</question>
  938. <answer>
  939. <p>There is a bug in the Solaris reference implementation of
  940. the JDK (see <a href="http://developer.java.sun.com/developer/bugParade/bugs/4230399.html">http://developer.java.sun.com/developer/bugParade/bugs/4230399.html</a>).
  941. This also appears to be true under Linux. Moving the JDK to
  942. the front of the PATH fixes the problem.</p>
  943. </answer>
  944. </faq>
  945. <faq id="delegating-classloader">
  946. <question>&lt;style&gt; or &lt;junit&gt; ignores my
  947. &lt;classpath&gt;</question>
  948. <answer>
  949. <p>These tasks don&apos;t ignore your classpath setting, you
  950. are facing a common problem with delegating classloaders.</p>
  951. <p>First of all let&apos;s state that Ant adds all
  952. <code>.jar</code> files from <code>ANT_HOME/lib</code> to
  953. <code>CLASSPATH</code>, therefore &quot;in
  954. <code>CLASSPATH</code>&quot; shall mean &quot;either in your
  955. <code>CLASSPATH</code> environment variable or
  956. <code>ANT_HOME/lib</code>&quot; for the rest of this
  957. answer.</p>
  958. <p>Technically the sentence above isn&apos;t true for Ant 1.6
  959. and later anymore, but the result is the same. For the sake
  960. of this discussion, <code>CLASSPATH</code> and
  961. <code>ANT_HOME/lib</code> are identical.</p>
  962. <p>This question collects a common type of problem: A task
  963. needs an external library and it has a nested classpath
  964. element so that you can point it to this external library, but
  965. that doesn&apos;t work unless you put the external library into the
  966. <code>CLASSPATH</code>.</p>
  967. <p>The root of the problem is that the class that needs the
  968. external library is on the <code>CLASSPATH</code>.</p>
  969. <p>When you specify a nested <code>&lt;classpath&gt;</code> in
  970. Ant, Ant creates a new class loader that uses the path you
  971. have specified. It then tries to load additional classes from
  972. this classloader.</p>
  973. <p>In most cases - for example the two cases above - Ant
  974. doesn&apos;t load the external library directly, it is the loaded
  975. class that does so.</p>
  976. <p>In the case of <code>&lt;junit&gt;</code> it is the task
  977. implementation itself and in the case of
  978. <code>&lt;style&gt;</code> it is the implementation of the
  979. <code>org.apache.tools.ant.taskdefs.XSLTLiaison</code>
  980. class.</p>
  981. <p>Ant&apos;s class loader implementation uses Java&apos;s
  982. delegation model, see <a
  983. href="http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html">http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html</a>
  984. the paragraph</p>
  985. <blockquote>The <code>ClassLoader</code> class uses a
  986. delegation model to search for classes and resources. Each
  987. instance of <code>ClassLoader</code> has an associated parent
  988. class loader. When called upon to find a class or resource, a
  989. <code>ClassLoader</code> instance will delegate the search for
  990. the class or resource to its parent class loader before
  991. attempting to find the class or resource itself. The virtual
  992. machine&apos;s built-in class loader, called the bootstrap
  993. class loader, does not itself have a parent but may serve as
  994. the parent of a <code>ClassLoader</code>
  995. instance.</blockquote>
  996. <p>This means, Ant&apos;s class loader will consult the
  997. bootstrap class loader first, which tries to load classes from
  998. <code>CLASSPATH</code>. The bootstrap class loader
  999. doesn&apos;t know anything about Ant&apos;s class loader or
  1000. even the path you have specified.</p>
  1001. <p>If the bootstrap class loader can load the class Ant has
  1002. asked it to load, this class will try to load the external
  1003. library from <code>CLASSPATH</code> as well - it doesn&apos;t
  1004. know anything else - and will not find it unless the library
  1005. is in <code>CLASSPATH</code> as well.</p>
  1006. <p>To solve this, you have two major options:</p>
  1007. <ol>
  1008. <li>put all external libraries you need in
  1009. <code>CLASSPATH</code> as well this is not what you want,
  1010. otherwise you wouldn&apos;t have found this FAQ entry.</li>
  1011. <li>remove the class that loads the external library from
  1012. the <code>CLASSPATH</code>.</li>
  1013. </ol>
  1014. <p><strong>Using The Second Option with Ant 1.5.4 and
  1015. Earlier:</strong></p>
  1016. <p>The easiest way to do this is to remove
  1017. <code>optional.jar</code> from <code>ANT_HOME/lib</code>. If
  1018. you do so, you will have to <code>&lt;taskdef&gt;</code> all
  1019. optional tasks and use nested <code>&lt;classpath&gt;</code>
  1020. elements in the <code>&lt;taskdef&gt;</code> tasks that point
  1021. to the new location of <code>optional.jar</code>. Also,
  1022. don&apos;t forget to add the new location of
  1023. <code>optional.jar</code> to the
  1024. <code>&lt;classpath&gt;</code> of your
  1025. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code>
  1026. task.</p>
  1027. <p>If you want to avoid to <code>&lt;taskdef&gt;</code> all
  1028. optional tasks you need, the only other option is to remove
  1029. the classes that should not be loaded via the bootstrap class
  1030. loader from <code>optional.jar</code> and put them into a
  1031. separate archive. Add this separate archive to the
  1032. <code>&lt;classpath&gt;</code> of your
  1033. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code> task
  1034. - and make sure the separate archive is not in
  1035. <code>CLASSPATH</code>.</p>
  1036. <p>In the case of <code>&lt;junit&gt;</code> you&apos;d have
  1037. to remove all classes that are in the
  1038. <code>org/apache/tools/ant/taskdefs/optional/junit</code>
  1039. directory, in the <code>&lt;style&gt;</code> case it is one of
  1040. the <code>*Liaison</code> classes in
  1041. <code>org/apache/tools/ant/taskdefs/optional</code>.</p>
  1042. <p><strong>Using The Second Option with Ant 1.6 and
  1043. later:</strong></p>
  1044. <p>In Ant 1.6 <code>optional.jar</code> has been split into
  1045. multiple jars, each one containing classes with the same
  1046. dependencies on external libraries. You can move the
  1047. "offending" jar out of ANT_HOME/lib. For the
  1048. <code>&lt;junit&gt;</code> task it would be
  1049. <code>ant-junit.jar</code> and for <code>&lt;style&gt;</code>
  1050. it would be <code>ant-trax.jar</code>,
  1051. <code>ant-xalan1.jar</code> or <code>ant-xslp.jar</code> -
  1052. depending on the processor you use.</p>
  1053. <p>If you use the option to break up <code>optional.jar</code>
  1054. for <code>&lt;junit&gt;</code> or remove
  1055. <code>ant-junit.jar</code>, you still have to use a
  1056. <code>&lt;taskdef&gt;</code> with a nested
  1057. <code>&lt;classpath&gt;</code> to define the junit task.</p>
  1058. </answer>
  1059. </faq>
  1060. <faq id="winxp-jdk14-ant14">
  1061. <question>When running Ant 1.4 on Windows XP and JDK 1.4, I get
  1062. various errors when trying to <code>&lt;exec&gt;</code>, fork
  1063. <code>&lt;java&gt;</code> or access environment
  1064. variables.</question>
  1065. <answer>
  1066. <p>Ant &lt; 1.5 doesn&apos;t recognize Windows XP as a flavor
  1067. of Windows that runs <code>CMD.EXE</code> instead of
  1068. <code>COMMAND.COM</code>. JDK 1.3 will tell Ant that Windows
  1069. XP is Windows 2000 so the problem doesn&apos;t show up
  1070. there.</p>
  1071. <p>Apart from upgrading to Ant 1.5 or better, setting the
  1072. environment variable <code>ANT_OPTS</code> to
  1073. <code>-Dos.name=Windows_NT</code> prior to invoking Ant has
  1074. been confirmed as a workaround.</p>
  1075. </answer>
  1076. </faq>
  1077. <faq id="1.5-cygwin-sh">
  1078. <question>The <code>ant</code> wrapper script of Ant 1.5 fails
  1079. for Cygwin if <code>ANT_HOME</code> is set to a Windows style
  1080. path.</question>
  1081. <answer>
  1082. <p>This problem has been reported only hours after Ant 1.5 has
  1083. been released, see <a
  1084. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=10664">Bug
  1085. 10664</a> and all its duplicates.</p>
  1086. <p>A fixed version of the wrapper script can be found <a
  1087. href="http://ant.apache.org/old-releases/v1.5/errata/">here</a>.
  1088. Simply replace your script with this version.</p>
  1089. </answer>
  1090. </faq>
  1091. <faq id="1.5.2-zip-broken">
  1092. <question><code>&lt;zip&gt;</code> is broken in Ant 1.5.2.</question>
  1093. <answer>
  1094. <p>Yes, it is.</p>
  1095. <p>The problem reported by most people - see <a
  1096. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17648">Bug
  1097. 17648</a> and all its duplicates - is that Ant creates
  1098. archives that a partially unreadable by WinZIP. Luckily
  1099. <code>jar</code> deals with the archives and so the generated
  1100. jars/wars/ears will most likely work for you anyway.</p>
  1101. <p>There are additional problems, see bugs <a
  1102. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17780">Bug
  1103. 17780</a>, <a
  1104. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17871">Bug
  1105. 17871</a> and <a
  1106. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=18403">Bug
  1107. 18403</a>. All of them are supposed to be fixed with Ant
  1108. 1.5.3 (and only 18403 should exist in 1.5.3beta1).</p>
  1109. </answer>
  1110. </faq>
  1111. <faq id="unknownelement.taskcontainer">
  1112. <question>
  1113. Why do my custom task containers see Unknown Elements in Ant 1.6
  1114. - they worked in Ant 1.5?
  1115. </question>
  1116. <answer>
  1117. <p>
  1118. The objects added in TaskContainer.addTask(Task task)
  1119. have changed from Tasks to UnknownElements.
  1120. </p>
  1121. <p>
  1122. There was a number of valid reasons for this change. But the backward
  1123. compatibility problems were not noticed until after Ant 1.6.0 was
  1124. released.
  1125. </p>
  1126. <p>
  1127. Your container class will need to be modified to check if the Task
  1128. is an UnknownElement and call perform on it to
  1129. convert it to a Task and to execute it.
  1130. (see apache.tools.ant.taskdefs.Sequential)
  1131. </p>
  1132. <p>
  1133. If you want to do more processing on the task,
  1134. you need to use the techniques in apache.tools.ant.taskdefs.Antlib#execute()
  1135. This does make use of one 1.6 method call (UE#getRealObject()),
  1136. you need to use UE#getTask() instead - this will
  1137. return null for non tasks (types like fileset id=x).
  1138. </p>
  1139. <p>
  1140. So.. iterate over the tasks, if they are UEs, convert them to
  1141. tasks, using UE#maybeConfigure and UE#getTask()
  1142. </p>
  1143. <source><![CDATA[
  1144. for (Iterator i = tasks.iterator(); i.hasNext();) {
  1145. Task t = (Task) i.next();
  1146. if (t instanceof UnknownElement) {
  1147. ((UnknownElement) t).maybeConfigure();
  1148. t = ((UnknownElement) t).getTask();
  1149. if (t == null) {
  1150. continue;
  1151. }
  1152. }
  1153. // .... original Custom code
  1154. }
  1155. ]]></source>
  1156. <p>
  1157. This approach should work for ant1.5 and ant1.6.
  1158. </p>
  1159. </answer>
  1160. </faq>
  1161. </faqsection>
  1162. </document>