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 69 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891
  1. <?xml version="1.0"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <document>
  17. <properties>
  18. <author email="bodewig@apache.org">Stefan Bodewig</author>
  19. <title>Frequently Asked Questions</title>
  20. </properties>
  21. <faqsection title="About this FAQ">
  22. <faq id="latest-version">
  23. <question>Where do I find the latest version of this
  24. document?</question>
  25. <answer>
  26. <p>The latest version can always be found at Ant&apos;s homepage
  27. <a href="http://ant.apache.org/faq.html">http://ant.apache.org/faq.html</a>.</p>
  28. </answer>
  29. </faq>
  30. <faq id="adding-faqs">
  31. <question>How can I contribute to this FAQ?</question>
  32. <answer>
  33. <p>The page you are looking it is generated from
  34. <a href="http://svn.apache.org/repos/asf/ant/core/trunk/xdocs/faq.xml">this</a>
  35. document. If you want to add a new question, please submit
  36. a patch against this document to one of Ant&apos;s mailing lists;
  37. hopefully, the structure is self-explanatory.</p>
  38. <p>If you don&apos;t know how to create a patch, see the patches
  39. section of <a href="http://jakarta.apache.org/site/source.html">this
  40. page</a>.</p>
  41. </answer>
  42. </faq>
  43. <faq id="creating-faq">
  44. <question>How do you create the HTML version of this
  45. FAQ?</question>
  46. <answer>
  47. <p>We use
  48. <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a>
  49. to render the HTML version from the original XML file.</p>
  50. <p>The Velocity stylesheets used to process the XML files can
  51. be found in the <code>xdocs/stylesheets</code> subdirectory of
  52. Ant&apos;s SVN repository - the build file
  53. <code>docs.xml</code> at the top level of the ant SVN
  54. module (trunk) is used to drive Anakia.</p>
  55. <p>This file assumes that you have the
  56. <code>jakarta-site2</code> CVS module checked out as well, but
  57. if you follow the instruction from Anakia&apos;s homepage, you
  58. should get it to work without that. Just make sure all
  59. required jars are in the task&apos;s classpath.</p>
  60. </answer>
  61. </faq>
  62. </faqsection>
  63. <faqsection title="General">
  64. <faq id="what-is-ant">
  65. <question>What is Apache Ant?</question>
  66. <answer>
  67. <p> Ant is a Java-based build tool. In theory, it is kind of
  68. like Make, without Make&apos;s wrinkles and with the full
  69. portability of pure Java code.</p>
  70. </answer>
  71. </faq>
  72. <faq id="ant-name">
  73. <question>Why do you call it Ant?</question>
  74. <answer>
  75. <p>According to Ant&apos;s original author, James Duncan
  76. Davidson, the name is an acronym for &quot;Another Neat
  77. Tool&quot;.</p>
  78. <p>Later explanations go along the lines of &quot;ants
  79. do an extremely good job at building things&quot;, or
  80. &quot;ants are very small and can carry a weight dozens of times
  81. their own&quot; - describing what Ant is intended to
  82. be.</p>
  83. </answer>
  84. </faq>
  85. <faq id="history">
  86. <question>Tell us a little bit about Ant&apos;s history.</question>
  87. <answer>
  88. <p>Initially, Ant was part of the Tomcat code base, when it was
  89. donated to the Apache Software Foundation. It was
  90. created by James Duncan Davidson, who is also the original
  91. author of Tomcat. Ant was there to build Tomcat, nothing
  92. else.</p>
  93. <p>Soon thereafter, several open source Java projects realized
  94. that Ant could solve the problems they had with Makefiles.
  95. Starting with the projects hosted at Jakarta and the old Java
  96. Apache project, Ant spread like a virus and is now the build
  97. tool of choice for a lot of projects.</p>
  98. <p>In January 2000, Ant was moved to a separate CVS module and
  99. was promoted to a project of its own, independent of
  100. Tomcat, and became Apache Ant.</p>
  101. <p>The first version of Ant that was exposed to a larger audience
  102. was the one that shipped with Tomcat&apos;s 3.1 release on 19 April
  103. 2000. This version has later been referred to as Ant
  104. 0.3.1.</p>
  105. <p>The first official release of Ant as a stand-alone product was
  106. Ant 1.1, released on 19 July 2000. The complete release
  107. history:</p>
  108. <table>
  109. <tr>
  110. <th>Ant Version</th>
  111. <th>Release Date</th>
  112. </tr>
  113. <tr>
  114. <td>1.1</td>
  115. <td>19 July 2000</td>
  116. </tr>
  117. <tr>
  118. <td>1.2</td>
  119. <td>24 October 2000</td>
  120. </tr>
  121. <tr>
  122. <td>1.3</td>
  123. <td>3 March 2001</td>
  124. </tr>
  125. <tr>
  126. <td>1.4</td>
  127. <td>3 September 2001</td>
  128. </tr>
  129. <tr>
  130. <td>1.4.1</td>
  131. <td>11 October 2001</td>
  132. </tr>
  133. <tr>
  134. <td>1.5</td>
  135. <td>10 July 2002</td>
  136. </tr>
  137. <tr>
  138. <td>1.5.1</td>
  139. <td>3 October 2002</td>
  140. </tr>
  141. <tr>
  142. <td>1.5.2</td>
  143. <td>3 March 2003</td>
  144. </tr>
  145. <tr>
  146. <td>1.5.3</td>
  147. <td>9 April 2003</td>
  148. </tr>
  149. <tr>
  150. <td>1.5.4</td>
  151. <td>12 August 2003</td>
  152. </tr>
  153. <tr>
  154. <td>1.6.0</td>
  155. <td>18 December 2003</td>
  156. </tr>
  157. <tr>
  158. <td>1.6.1</td>
  159. <td>12 February 2004</td>
  160. </tr>
  161. <tr>
  162. <td>1.6.2</td>
  163. <td>16 July 2004</td>
  164. </tr>
  165. <tr>
  166. <td>1.6.3</td>
  167. <td>28 April 2005</td>
  168. </tr>
  169. <tr>
  170. <td>1.6.4</td>
  171. <td>19 May 2005</td>
  172. </tr>
  173. <tr>
  174. <td>1.6.5</td>
  175. <td>2 June 2005</td>
  176. </tr>
  177. <tr>
  178. <td>1.7.0</td>
  179. <td>19 December 2006</td>
  180. </tr>
  181. <tr>
  182. <td>1.7.1</td>
  183. <td>27 June 2008</td>
  184. </tr>
  185. </table>
  186. </answer>
  187. </faq>
  188. </faqsection>
  189. <faqsection title="Installation">
  190. <faq id="java-version">
  191. <question>Which version of Java is required to run
  192. Ant?</question>
  193. <answer>
  194. <p>You will need Java installed on your system, version 1.3 or
  195. later required, 1.5 or later strongly recommended. The later
  196. the version of Java, the more Ant tasks you get.</p>
  197. <p>If only the JRE is present but not a full JDK then many
  198. tasks will not work.</p>
  199. <p>Ant 1.6.* works with jdk 1.2 and higher, Ant 1.1 to Ant
  200. 1.5.* work with jdk 1.1 and higher.</p>
  201. </answer>
  202. </faq>
  203. <faq id="no-gnu-tar">
  204. <question>I get checksum errors when I try to extract the
  205. <code>tar.gz</code> distribution file. Why?</question>
  206. <answer>
  207. <p>Ant&apos;s distribution contains file names that are longer
  208. than 100 characters, which is not supported by the standard
  209. tar file format. Several different implementations of tar use
  210. different and incompatible ways to work around this
  211. restriction.</p>
  212. <p>Ant&apos;s &lt;tar&gt; task can create tar archives that use
  213. the GNU tar extension, and this has been used when putting
  214. together the distribution. If you are using a different
  215. version of tar (for example, the one shipping with Solaris),
  216. you cannot use it to extract the archive.</p>
  217. <p>The solution is to either install GNU tar, which can be
  218. found <a href="http://www.gnu.org/software/tar/tar.html">here</a>,
  219. or use the zip archive instead (you can extract it using
  220. <code>jar xf</code>).</p>
  221. </answer>
  222. </faq>
  223. <faq id="RedHat_ES_3">
  224. <question>How do you get ant-1.6.x (or any version later than
  225. 1.5.2) to work on on RedHat ES 3?</question>
  226. <answer>
  227. <p>Redhat ES 3.0 comes installed with ant 1.5.2. Even if you
  228. have your PATH and ANT_HOME variables set correctly to a later
  229. version of ant, you will always be forced to use the
  230. preinstalled version.</p>
  231. <p>To use a later version of ant on this OS you could do the
  232. following:</p>
  233. <source><![CDATA[
  234. $ ant -version
  235. Apache Ant version 1.5.2-23 compiled on November 12 2003
  236. $ su -
  237. # rpm -e ant ant-libs
  238. # exit
  239. $ hash -r
  240. $ ant -version
  241. Apache Ant version 1.6.2 compiled on July 16 2004
  242. ]]></source></answer>
  243. </faq>
  244. </faqsection>
  245. <faqsection title="How do I ...">
  246. <faq id="implement-os-specific-configuration">
  247. <question>How do I realize os--specific configurations?</question>
  248. <answer>
  249. <p>The core idea is using property files which name accords to the
  250. os-name. Then simply use the build-in property <tt>os.name</tt>.</p>
  251. <p>For better use you should also provide a file with default values.
  252. But be careful with the correct os-names. For test simply &lt;echo&gt;
  253. the ${os.name} on all machines and you can be sure to use the right
  254. file names.</p>
  255. <source><![CDATA[
  256. <property file="${os.name}.properties"/>
  257. <property file="default.properties"/>
  258. ]]></source>
  259. </answer>
  260. </faq>
  261. <faq id="adding-external-tasks">
  262. <question>How do I add an external task that I&apos;ve written to the
  263. page &quot;External Tools and Tasks&quot;?</question>
  264. <answer>
  265. <p>Join and post a message to the dev or user mailing
  266. list (one list is enough), including the following
  267. information:</p>
  268. <ul>
  269. <li>the name of the task/tool</li>
  270. <li>a short description of the task/tool</li>
  271. <li>a Compatibility: entry stating with which version(s) of
  272. Ant the tool/task is compatible to</li>
  273. <li>a URL: entry linking to the main page of the tool/task</li>
  274. <li>a Contact: entry containing the email address or the URL
  275. of a webpage for the person or list to contact for issues
  276. related to the tool/task. <strong>Note that we&apos;ll add a
  277. link on the page, so any email address added there is not
  278. obfuscated and can (and probably will) be abused by robots
  279. harvesting websites for addresses to spam.</strong></li>
  280. <li>a License: entry containing the type of license for the
  281. tool/task</li>
  282. </ul>
  283. <p>The preferred format for this information is a patch to <a
  284. href="http://svn.apache.org/repos/asf/ant/core/trunk/xdocs/external.xml">this</a>
  285. document.</p>
  286. <p>If you have written something bigger than a 'simple plugin' to Ant it
  287. may be better to add the link to <a href="projects.html">projects.html</a>.
  288. The procedure to add it is the same. The file to patch is <a
  289. href="http://svn.apache.org/repos/asf/ant/core/trunk/xdocs/projects.xml">this</a>
  290. document. The syntax of that file is the same.</p>
  291. </answer>
  292. </faq>
  293. <faq id="create-extensions">
  294. <question>How do I create new tasks?</question>
  295. <answer>
  296. <p>Apart from a lot of information on using Ant, the
  297. <a href="manual/index.html">Manual</a> also contains information
  298. on how to extend Ant with new tasks. This information
  299. can be found under &quot;Developing with Ant&quot;.</p>
  300. <p>Chances are that someone else already created the task you
  301. want to create, it may be wise to see
  302. <a href="external.html">External Tools and Tasks</a> and
  303. <a href="projects.html">Related Projects</a> first.</p>
  304. </answer>
  305. </faq>
  306. <faq id="passing-cli-args">
  307. <question>How do I pass parameters from the command line to my
  308. build file?</question>
  309. <answer>
  310. <p>Use properties. Using <code>ant
  311. -D<em>name</em>=<em>value</em></code> lets you define values for
  312. properties on the Ant command line. These properties can then be
  313. used within your build file as
  314. any normal property: <code>${<em>name</em>}</code> will put in
  315. <code><em>value</em></code>.</p>
  316. </answer>
  317. </faq>
  318. <faq id="jikes-switches">
  319. <question>How can I use Jikes-specific command-line
  320. switches?</question>
  321. <answer>
  322. <p>A couple of switches are supported via &quot;magic&quot;
  323. properties:</p>
  324. <table>
  325. <tr>
  326. <th>switch</th>
  327. <th>property</th>
  328. <th>default</th>
  329. </tr>
  330. <tr>
  331. <td>+E</td>
  332. <td>build.compiler.emacs</td>
  333. <td>false == not set</td>
  334. </tr>
  335. <tr>
  336. <td>+P</td>
  337. <td>build.compiler.pedantic</td>
  338. <td>false == not set</td>
  339. </tr>
  340. <tr>
  341. <td>+F</td>
  342. <td>build.compiler.fulldepend</td>
  343. <td>false == not set</td>
  344. </tr>
  345. <tr>
  346. <td><strong>(Only for Ant &lt; 1.4; replaced by the
  347. <code><strong>nowarn</strong></code>
  348. attribute of the <code><strong>&lt;javac&gt;</strong></code>
  349. task after that.)</strong><br></br>-nowarn</td>
  350. <td>build.compiler.warnings</td>
  351. <td>true == not set</td>
  352. </tr>
  353. </table>
  354. <p>With Ant &gt;= 1.5, you can also use nested
  355. <code>&lt;compilerarg&gt;</code> elements with the
  356. <code>&lt;javac&gt;</code> task.</p>
  357. </answer>
  358. </faq>
  359. <faq id="shell-redirect-1">
  360. <question>How do I include a &lt; character in my command-line arguments?</question>
  361. <answer>
  362. <p>The short answer is "Use: <code>&amp;lt;</code>".</p>
  363. <p>The long answer is that this probably won&apos;t do what you
  364. want anyway (see <a href="#shell-redirect-2">the next
  365. section</a>).</p>
  366. </answer>
  367. </faq>
  368. <faq id="shell-redirect-2">
  369. <question>How do I redirect standard input or standard output
  370. in the <code>&lt;exec&gt;</code> task?</question>
  371. <answer>
  372. <p>Say you want to redirect the standard output stream of the
  373. <code>m4</code> command to write to a file, something
  374. like:</p>
  375. <source><![CDATA[
  376. shell-prompt> m4 foo.m4 > foo
  377. ]]></source>
  378. <p>and try to translate it into</p>
  379. <source><![CDATA[
  380. <exec executable="m4">
  381. <arg value="foo.m4"/>
  382. <arg value="&gt;"/>
  383. <arg value="foo"/>
  384. </exec>
  385. ]]></source>
  386. <p>This will not do what you expect. The output redirection is
  387. performed by your shell, not the command itself, so this
  388. should read:</p>
  389. <source><![CDATA[
  390. <exec executable="/bin/sh">
  391. <arg value="-c" />
  392. <arg value="m4 foo.m4 &gt; foo" />
  393. </exec>
  394. ]]></source>
  395. <p>Note that you must use the <code>value</code> attribute of
  396. <code>&lt;arg&gt;</code> in the last element, in order to have
  397. the command passed as a single, quoted argument. Alternatively,
  398. you can use:</p>
  399. <source><![CDATA[
  400. <exec executable="/bin/sh">
  401. <arg line='-c "m4 foo.m4 &gt; foo"'/>
  402. </exec>
  403. ]]></source>
  404. <p>Note the double-quotes nested inside the single-quotes.</p>
  405. </answer>
  406. </faq>
  407. <faq id="batch-shell-execute">
  408. <question>How do I execute a batch file or shell script from Ant?</question>
  409. <answer>
  410. <p>On native Unix systems, you should be able to run shell scripts
  411. directly. On systems running a Unix-type shell (for example, Cygwin
  412. on Windows) execute the (command) shell instead - <code>cmd</code>
  413. for batch files, <code>sh</code> for shell scripts - then pass the
  414. batch file or shell script (plus any arguments to the script)
  415. as a single command, using the <code>/c</code> or
  416. <code>-c</code> switch, respectively. See
  417. <a href="#shell-redirect-2">the above section</a>
  418. for example <code>&lt;exec&gt;</code> tasks
  419. executing <code>sh</code>. For batch files, use something like:</p>
  420. <source><![CDATA[
  421. <exec dir="." executable="cmd" os="Windows NT">
  422. <arg line="/c test.bat"/>
  423. </exec>
  424. ]]></source>
  425. </answer>
  426. </faq>
  427. <faq id="multi-conditions">
  428. <question>I want to execute a particular target only if
  429. multiple conditions are true.</question>
  430. <answer>
  431. <p>There are actually several answers to this question.</p>
  432. <p>If you have only one set and one unset property to test,
  433. you can specify both an <code>if</code> and an <code>unless</code>
  434. attribute for the target, and they will act as if they
  435. are &quot;anded&quot; together.</p>
  436. <p>If you are using a version of Ant 1.3 or earlier, the
  437. way to work with all other cases is to chain targets together
  438. to determine the specific state you want to test for.</p>
  439. <p>To see how this works, assume you have three properties:
  440. <code>prop1</code>, <code>prop2</code>, and <code>prop3</code>.
  441. You want to test that <code>prop1</code> and <code>prop2</code>
  442. are set, and that <code>prop3</code> is not. If the condition
  443. holds true you want to echo &quot;yes&quot;.</p>
  444. <p>Here is the implementation in Ant 1.3 and earlier:</p>
  445. <source><![CDATA[
  446. <target name="cond" depends="cond-if"/>
  447. <target name="cond-if" if="prop1">
  448. <antcall target="cond-if-2"/>
  449. </target>
  450. <target name="cond-if-2" if="prop2">
  451. <antcall target="cond-if-3"/>
  452. </target>
  453. <target name="cond-if-3" unless="prop3">
  454. <echo message="yes"/>
  455. </target>
  456. ]]></source>
  457. <p>Note: <code>&lt;antcall&gt;</code> tasks do <em>not</em> pass
  458. property changes back up to the environment they were called
  459. from, so you wouldn&apos;t be able to, for example, set a
  460. <code>result</code> property in the <code>cond-if-3</code> target,
  461. then do
  462. <code>&lt;echo message=&quot;result is ${result}&quot;/&gt;</code>
  463. in the <code>cond</code> target.</p>
  464. <p>Starting with Ant 1.4, you can use the
  465. <code>&lt;condition&gt;</code> task.</p>
  466. <source><![CDATA[
  467. <target name="cond" depends="cond-if,cond-else"/>
  468. <target name="check-cond">
  469. <condition property="cond-is-true">
  470. <and>
  471. <not>
  472. <equals arg1="${prop1}" arg2="$${prop1}" />
  473. </not>
  474. <not>
  475. <equals arg1="${prop2}" arg2="$${prop2}" />
  476. </not>
  477. <equals arg1="${prop3}" arg2="$${prop3}" />
  478. </and>
  479. </condition>
  480. </target>
  481. <target name="cond-if" depends="check-cond" if="cond-is-true">
  482. <echo message="yes"/>
  483. </target>
  484. <target name="cond-else" depends="check-cond" unless="cond-is-true">
  485. <echo message="no"/>
  486. </target>
  487. ]]></source>
  488. <p>This version takes advantage of two things:</p>
  489. <ul>
  490. <li>If a property <code>a</code> has not been set,
  491. <code>${a}</code> will evaluate to <code>${a}</code>.</li>
  492. <li>To get a literal <code>$</code> in Ant, you have to
  493. escape it with another <code>$</code> - this will also break
  494. the special treatment of the <code>${</code> sequence.</li>
  495. </ul>
  496. <p>Because testing for a literal <code>${property}</code> string
  497. isn&apos;t all that readable or easy to understand,
  498. post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element
  499. to the <code>&lt;condition&gt;</code> task.</p>
  500. <p>Here is the previous example done using
  501. <code>&lt;isset&gt;</code>:</p>
  502. <source><![CDATA[
  503. <target name="check-cond">
  504. <condition property="cond-is-true">
  505. <and>
  506. <isset property="prop1"/>
  507. <isset property="prop2"/>
  508. <not>
  509. <isset property="prop3"/>
  510. </not>
  511. </and>
  512. </condition>
  513. </target>
  514. ]]></source>
  515. <p>The last option is to use a scripting language to set the
  516. properties. This can be particularly handy when you need much
  517. finer control than the simple conditions shown here but, of
  518. course, comes with the overhead of adding JAR files to support
  519. the language, to say nothing of the added maintenance in requiring
  520. two languages to implement a single system. See the
  521. <a href="manual/OptionalTasks/script.html">
  522. <code>&lt;script&gt;</code> task documentation</a> for more
  523. details.</p>
  524. </answer>
  525. </faq>
  526. <faq id="encoding">
  527. <question>How can I include national characters like German
  528. umlauts in my build file?</question>
  529. <answer>
  530. <p>You need to tell the XML parser which character encoding
  531. your build file uses, this is done inside the <a
  532. href="http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd">XML
  533. declaration</a>.</p>
  534. <p>By default the parser assumes you are using the UTF-8
  535. encoding instead of your platform&apos;s default. For most Western
  536. European countries you should set the encoding to
  537. <code>ISO-8859-1</code>. To do so, make the very first line
  538. of you build file read like</p>
  539. <source><![CDATA[
  540. <?xml version="1.0" encoding="ISO-8859-1" ?>
  541. ]]></source>
  542. </answer>
  543. </faq>
  544. <faq id="use-zip-instead-of-jar">
  545. <question>How do I use <code>jar</code>&apos;s <code>M</code> switch?
  546. I don&apos;t want a MANIFEST.</question>
  547. <answer>
  548. <p>A JAR archive is a ZIP file, so if you don&apos;t want a
  549. MANIFEST you can simply use <code>&lt;zip&gt;</code>.</p>
  550. <p>If your file names contain national characters you should
  551. know that Sun&apos;s <code>jar</code> utility like Ant&apos;s
  552. <code>&lt;jar&gt;</code> uses UTF-8 to encode their names while
  553. <code>&lt;zip&gt;</code> uses your platforms default encoding.
  554. Use the encoding attribute of <code>&lt;zip&gt;</code> if
  555. necessary.</p>
  556. </answer>
  557. </faq>
  558. <faq id="propertyvalue-as-name-for-property">
  559. <question>How can I do something like <code>&lt;property name="prop"
  560. value="${${anotherprop}}"/&gt;</code> (double expanding the property)?</question>
  561. <answer>
  562. <p>Without any external help you can not.</p>
  563. <p>With &lt;script/&gt;, which needs external libraries, you can do</p>
  564. <source><![CDATA[
  565. <script language="javascript">
  566. propname = project.getProperty("anotherprop");
  567. project.setNewProperty("prop", propname);
  568. </script>
  569. ]]></source>
  570. <p>With AntContrib (external task library) you can do <code>
  571. &lt;propertycopy name="prop" from="${anotherprop}"/&gt;</code>.</p>
  572. <p>With Ant 1.6 you can simulate the AntContribs &lt;propertycopy&gt;
  573. and avoid the need of an external library:</p>
  574. <source><![CDATA[
  575. <macrodef name="propertycopy">
  576. <attribute name="name"/>
  577. <attribute name="from"/>
  578. <sequential>
  579. <property name="@{name}" value="${@{from}}"/>
  580. </sequential>
  581. </macrodef>
  582. ]]></source>
  583. </answer>
  584. </faq>
  585. <faq id="delete-directory-children-only">
  586. <question>How can I delete everything beneath a particular directory,
  587. preserving the directory itself?</question>
  588. <answer>
  589. <p>Most users who go down this path have no problem figuring out that
  590. <code>&lt;delete includeemptydirs="true" /&gt;</code> will help them. The
  591. seemingly tricky part is preserving the base directory itself,
  592. which Ant includes in the directory scan. Fortunately the answer is simple:
  593. </p>
  594. <source><![CDATA[
  595. <delete includeemptydirs="true">
  596. <fileset dir="dirtokeep" includes="**/*" />
  597. </delete>
  598. ]]></source>
  599. </answer>
  600. </faq>
  601. </faqsection>
  602. <faqsection title="It doesn&apos;t work (as expected)">
  603. <faq id="general-advice">
  604. <question>General Advice</question>
  605. <answer>
  606. <p>There are many reasons why Ant doesn&apos;t behave as
  607. expected, not all of them are due to Ant bugs. See our <a
  608. href="problems.html">Having Problems?</a> page for hints that
  609. may help pinning down the reasons for your problem.</p>
  610. </answer>
  611. </faq>
  612. <faq id="always-recompiles">
  613. <question>Why does Ant always recompile all my Java files?</question>
  614. <answer>
  615. <p>In order to find out which files should be compiled, Ant
  616. compares the timestamps of the source files to those of the
  617. resulting <code>.class</code> files. Opening all source files
  618. to find out which package they belong to would be very
  619. inefficient. Instead, Ant expects you to place your
  620. source files in a directory hierarchy that mirrors your
  621. package hierarchy and to point Ant to the root of this
  622. directory tree with the <code>srcdir</code> attribute.</p>
  623. <p>Say you have <code>&lt;javac srcdir=&quot;src&quot;
  624. destdir=&quot;dest&quot;/&gt;</code>. If Ant finds a file
  625. <code>src/a/b/C.java</code>, it expects it to be in package
  626. <code>a.b</code> so that the resulting <code>.class</code>
  627. file is going to be <code>dest/a/b/C.class</code>.</p>
  628. <p>If your source-tree directory structure does not match your
  629. package structure, Ant&apos;s heuristic won&apos;t work, and
  630. it will recompile classes that are up-to-date. Ant is not the
  631. only tool that expects a source-tree layout like this.</p>
  632. <p>If you have Java source files that aren&apos;t declared to
  633. be part of any package, you can still use the <code>&lt;javac&gt;</code>
  634. task to compile these files correctly - just set the
  635. <code>srcdir</code> and <code>destdir</code> attributes to
  636. the actual directory the source
  637. files live in and the directory the class files should go into,
  638. respectively.</p>
  639. </answer>
  640. </faq>
  641. <faq id="defaultexcludes">
  642. <question>I&apos;ve used a <code>&lt;delete&gt;</code> task to
  643. delete unwanted SourceSafe control files (CVS files, editor
  644. backup files, etc.), but it doesn&apos;t seem to work; the files
  645. never get deleted. What&apos;s wrong?</question>
  646. <answer>
  647. <p>This is probably happening because, by default, Ant excludes
  648. SourceSafe control files (<code>vssver.scc</code>) and certain other
  649. files from FileSets.</p>
  650. <p>Here&apos;s what you probably did:</p>
  651. <source><![CDATA[
  652. <delete>
  653. <fileset dir="${build.src}" includes="**/vssver.scc"/>
  654. </delete>
  655. ]]></source>
  656. <p>You need to switch off the default exclusions,
  657. and it will work:</p>
  658. <source><![CDATA[
  659. <delete>
  660. <fileset dir="${build.src}" includes="**/vssver.scc"
  661. defaultexcludes="no"/>
  662. </delete>
  663. ]]></source>
  664. <p>For a complete listing of the patterns that are excluded
  665. by default, see <a href="manual/dirtasks.html#defaultexcludes">the user
  666. manual</a>.</p>
  667. </answer>
  668. </faq>
  669. <faq id="stop-dependency">
  670. <question>I have a target I want to skip if a property is set,
  671. so I have <code>unless=&quot;property&quot;</code> as an attribute
  672. of the target, but all the targets this target
  673. depends on are still executed. Why?</question>
  674. <answer>
  675. <p>The list of dependencies is generated by Ant before any of the
  676. targets are run. This allows dependent targets, such as an
  677. <code>init</code> target, to set properties that can control the
  678. execution of the targets higher in the dependency graph. This
  679. is a good thing.</p>
  680. <p>However, when your dependencies break down the
  681. higher-level task
  682. into several smaller steps, this behaviour becomes
  683. counter-intuitive. There are a couple of solutions available:
  684. </p>
  685. <ol>
  686. <li>Put the same condition on each of the dependent targets.</li>
  687. <li>Execute the steps using <code>&lt;antcall&gt;</code>,
  688. instead of specifying them inside the <code>depends</code>
  689. attribute.</li>
  690. </ol>
  691. </answer>
  692. </faq>
  693. <faq id="include-order">
  694. <question>In my <code>&lt;fileset&gt;</code>, I&apos;ve put in an
  695. <code>&lt;exclude&gt;</code> of all files followed by an
  696. <code>&lt;include&gt;</code> of just the files I want, but it
  697. isn&apos;t giving me any files at all. What&apos;s wrong?
  698. </question>
  699. <answer>
  700. <p>The order of the <code>&lt;include&gt;</code> and
  701. <code>&lt;exclude&gt;</code> tags within a <code>&lt;fileset&gt;</code>
  702. is ignored when the FileSet is created. Instead, all of the
  703. <code>&lt;include&gt;</code> elements are processed together,
  704. followed by all of the <code>&lt;exclude&gt;</code>
  705. elements. This means that the <code>&lt;exclude&gt;</code>
  706. elements only apply to the file list produced by the
  707. <code>&lt;include&gt;</code> elements.</p>
  708. <p>To get the files you want, focus on just the
  709. <code>&lt;include&gt;</code> patterns that would be necessary
  710. to get them. If you find you need to trim the list that the
  711. <code>&lt;include&gt;</code> elements produce, then use
  712. <code>&lt;exclude&gt;</code> elements.</p>
  713. </answer>
  714. </faq>
  715. <faq id="properties-not-trimmed">
  716. <question><code>ant</code> failed to build my program via javac
  717. even when I put the needed jars in an external
  718. <code>build.properties</code> file and reference them by
  719. <code>pathelement</code> or <code>classpath refid</code>.</question>
  720. <answer>
  721. <p>When <code>ant</code> loads properties from an external
  722. file it doesn&apos;t touch the value of properties, trailing blanks
  723. will not be trimmed for example.</p>
  724. <p>If the value represents a file path, like a jar needed to
  725. compile, the task which requires the value, javac for example
  726. would fail to compile since it can&apos;t find the file due to
  727. trailing spaces.</p>
  728. </answer>
  729. </faq>
  730. <faq id="winzip-lies">
  731. <question>Ant creates WAR files with a lower-case
  732. <code>web-inf</code> or JAR files with a lower-case
  733. <code>meta-inf</code> directory.</question>
  734. <answer>
  735. <p>No it doesn&apos;t.</p>
  736. <p>You may have seen these lower-case directory names in
  737. WinZIP, but WinZIP is trying to be helpful (and fails). If
  738. WinZIP encounters a filename that is all upper-case, it
  739. assumes it has come from an old DOS box and changes the case to
  740. all lower-case for you.</p>
  741. <p>If you extract (or just check) the archive with jar, you
  742. will see that the names have the correct case.</p>
  743. <p>With WinZIP (version 8.1 at least), this can be corrected in the
  744. configuration. In the Options/Configuration menu, in the View tab, General
  745. section, check the "Allow all upper case files names" box. The META-INF and
  746. WEB-INF will look correct.</p>
  747. </answer>
  748. </faq>
  749. <faq id="NoClassDefFoundError">
  750. <question>I installed Ant 1.6.x and now get
  751. <code>Exception in thread "main" java.lang.NoClassDefFoundError:
  752. </code>
  753. </question>
  754. <answer>
  755. <p>
  756. The cause of this is that there is an old version of ant somewhere in the
  757. class path or configuration.
  758. </p>
  759. <p>
  760. A version of this problem happens with jars that are in the classpath
  761. that include an embedded copy of ant classes.
  762. An example of this is some copies of weblogic.jar.
  763. </p>
  764. <p>
  765. One can check if this is the case by doing (on unix/sh):
  766. <code><pre>
  767. unset CLASSPATH
  768. ant -version
  769. </pre>
  770. </code>
  771. </p>
  772. </answer>
  773. </faq>
  774. <faq id="InstantiationException">
  775. <question>I installed Ant 1.6.x and now get
  776. <code>java.lang.InstantiationException: org.apache.tools.ant.Main</code>
  777. </question>
  778. <answer>
  779. <p>
  780. The cause of this is that there is an old version of ant somewhere in the
  781. class path or configuration.
  782. </p>
  783. <p>
  784. A version of this problem may be seen on some linux systems.
  785. Some linux systems (Fedora Core 2 for example), comes with a version
  786. of ant pre-installed. There is a configuration file called
  787. <code>/etc/ant.conf</code> which if present, the ant shell
  788. script will 'dot' include. On Fedora Core 2, the /etc/ant.conf
  789. file resets the <code>ANT_HOME</code> environment variable to
  790. <code>/usr/share/ant</code>. This causes the problem that
  791. an old version of ant (1.5.x in this cause) will be used
  792. with a new version of the ant script file.
  793. </p>
  794. <p>
  795. One can check if this is the case by doing
  796. <code>ant --noconfig -version</code>.
  797. </p>
  798. </answer>
  799. </faq>
  800. <faq id="mangled-manifest">
  801. <question>
  802. Whenever I use the Ant jar or manifest related tasks, long lines in
  803. my manifest are wrapped at 70 characters and the resulting jar does
  804. not work in my application server. Why does Ant do this?
  805. </question>
  806. <answer>
  807. <p>
  808. Ant implements the Java
  809. <a href="http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html">Jar
  810. file specification</a>. Please refer to the notes section where it
  811. discusses the maximum allowable length of a line and the concept of
  812. continuation characters.
  813. </p>
  814. <p>
  815. If a jar file produced by Ant does not work in your appserver, and
  816. that failure is due to the wrapped manifest, then you need
  817. to consult your appserver provider, as it is a bug in their
  818. appserver. Far more likely, however, is a problem in your
  819. specification of your classpath. It is not Ant's wrapping of your
  820. classpath that is the problem.
  821. </p>
  822. <p>
  823. Do not raise a bug about this issue until you have checked to ensure
  824. that the problem is not due to your classpath specification.
  825. </p>
  826. </answer>
  827. </faq>
  828. </faqsection>
  829. <faqsection title="Ant and IDEs/Editors">
  830. <faq id="integration">
  831. <question>Is Ant supported by my IDE/Editor?</question>
  832. <answer>
  833. <p>See the <a href="external.html#IDE and Editor Integration">section
  834. on IDE integration</a> on our External Tools and Tasks page.</p>
  835. </answer>
  836. </faq>
  837. <faq id="emacs-mode">
  838. <question>Why doesn&apos;t (X)Emacs/vi/MacOS X&apos;s project builder
  839. correctly parse the error messages generated by Ant?</question>
  840. <answer>
  841. <p>Ant adds a &quot;banner&quot; with the name of the current
  842. task in front of all logging messages - and there are no built-in
  843. regular expressions in your editor that would account for
  844. this.</p>
  845. <p>You can disable this banner by invoking Ant with the
  846. <code>-emacs</code> switch. To make Ant autodetect
  847. Emacs&apos; compile mode, put this into your
  848. <code>.antrc</code> (contributed by Ville Skytt&#228;).</p>
  849. <source><![CDATA[
  850. # Detect (X)Emacs compile mode
  851. if [ "$EMACS" = "t" ] ; then
  852. ANT_ARGS="$ANT_ARGS -emacs"
  853. ANT_OPTS="$ANT_OPTS -Dbuild.compiler.emacs=true"
  854. fi
  855. ]]></source>
  856. <p>Alternatively, you can add the following snippet to your
  857. <code>.emacs</code> to make Emacs understand Ant&apos;s
  858. output.</p>
  859. <source><![CDATA[
  860. (require 'compile)
  861. (setq compilation-error-regexp-alist
  862. (append (list
  863. ;; works for jikes
  864. '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3)
  865. ;; works for javac
  866. '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2))
  867. compilation-error-regexp-alist))
  868. ]]></source>
  869. <p>Yet another alternative that preserves most of Ant&apos;s
  870. formatting is to pipe Ant&apos;s output through the following Perl
  871. script by Dirk-Willem van Gulik:</p>
  872. <source><![CDATA[
  873. #!/usr/bin/perl
  874. #
  875. # May 2001 dirkx@apache.org - remove any
  876. # [foo] lines from the output; keeping
  877. # spacing more or less there.
  878. #
  879. $|=1;
  880. while(<STDIN>) {
  881. if (s/^(\s+)\[(\w+)\]//) {
  882. if ($2 ne $last) {
  883. print "$1\[$2\]";
  884. $s = ' ' x length($2);
  885. } else {
  886. print "$1 $s ";
  887. };
  888. $last = $2;
  889. };
  890. print;
  891. };
  892. ]]></source>
  893. </answer>
  894. </faq>
  895. </faqsection>
  896. <faqsection title="Advanced Issues">
  897. <faq id="dtd">
  898. <question>Is there a DTD that I can use to validate my build
  899. files?</question>
  900. <answer>
  901. <p>An incomplete DTD can be created by the
  902. <code>&lt;antstructure&gt;</code> task - but this one
  903. has a few problems:</p>
  904. <ul>
  905. <li>It doesn&apos;t know about required attributes. Only
  906. manual tweaking of this file can help here.</li>
  907. <li>It is not complete - if you add new tasks via
  908. <code>&lt;taskdef&gt;</code> it won&apos;t know about it. See
  909. <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this
  910. page</a> by Michel Casabianca for a solution to this
  911. problem. Note that the DTD you can download at this page
  912. is based on Ant 0.3.1.</li>
  913. <li>It may even be an invalid DTD. As Ant allows tasks
  914. writers to define arbitrary elements, name collisions will
  915. happen quite frequently - if your version of Ant contains
  916. the optional <code>&lt;test&gt;</code> and
  917. <code>&lt;junit&gt;</code> tasks, there are two XML
  918. elements named <code>test</code> (the task and the nested child
  919. element of <code>&lt;junit&gt;</code>) with different attribute
  920. lists. This problem cannot be solved; DTDs don&apos;t give a
  921. syntax rich enough to support this.</li>
  922. </ul>
  923. </answer>
  924. </faq>
  925. <faq id="xml-entity-include">
  926. <question>How do I include an XML snippet in my build file?</question>
  927. <answer>
  928. <p>You can use XML&apos;s way of including external files and let
  929. the parser do the job for Ant:</p>
  930. <source><![CDATA[
  931. <?xml version="1.0"?>
  932. <!DOCTYPE project [
  933. <!ENTITY common SYSTEM "common.xml">
  934. ]>
  935. <project name="test" default="test" basedir=".">
  936. <target name="setup">
  937. ...
  938. </target>
  939. &common;
  940. ...
  941. </project>
  942. ]]></source>
  943. <p>will literally include the contents of <code>common.xml</code> where
  944. you&apos;ve placed the <code>&amp;common;</code> entity.</p>
  945. <p>(The filename <code>common.xml</code> in this example is resolved
  946. relative to the containing XML file by the XML parser. You may also use
  947. an absolute <code>file:</code> protocol URI.)</p>
  948. <p>In combination with a DTD, this would look like this:</p>
  949. <source><![CDATA[
  950. <!DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "ant.dtd" [
  951. <!ENTITY include SYSTEM "header.xml">
  952. ]>
  953. ]]></source>
  954. <p>Starting with Ant 1.6, there is a new
  955. <code>&lt;import&gt;</code> task that can (also) be used to
  956. include build file fragments. Unlike the snippets used with
  957. entity includes, the referenced files have to be complete Ant
  958. build files, though.</p>
  959. <p>The example above would become:</p>
  960. <source><![CDATA[
  961. <?xml version="1.0"?>
  962. <project name="test" default="test" basedir=".">
  963. <target name="setup">
  964. ...
  965. </target>
  966. <import file="./common.xml"/>
  967. ...
  968. </project>
  969. ]]></source>
  970. <p>Unlike entity includes, <code>&lt;import&gt;</code> will
  971. let you use Ant properties in the file name.</p>
  972. </answer>
  973. </faq>
  974. <faq id="mail-logger">
  975. <question>How do I send an email with the result of my build
  976. process?</question>
  977. <answer>
  978. <p>If you are using a nightly build of Ant 1.5 after
  979. 2001-12-14, you can use the built-in MailLogger:</p>
  980. <source><![CDATA[
  981. ant -logger org.apache.tools.ant.listener.MailLogger
  982. ]]></source>
  983. <p>See the <a href="http://svn.apache.org/repos/asf/ant/core/trunk/docs/manual/listeners.html">Listeners
  984. &amp; Loggers</a> documentation for details on the properties
  985. required.</p>
  986. <p>For older versions of Ant, you can use a custom
  987. BuildListener that sends out an email
  988. in the buildFinished() method. Will Glozer
  989. &lt;will.glozer@jda.com&gt; has written such a listener based
  990. on <a href="http://java.sun.com/products/javamail/">JavaMail</a>.
  991. The source is:</p>
  992. <source><![CDATA[
  993. import java.io.*;
  994. import java.util.*;
  995. import javax.mail.*;
  996. import javax.mail.internet.*;
  997. import org.apache.tools.ant.*;
  998. /**
  999. * A simple listener that waits for a build to finish and sends an email
  1000. * of the results. The settings are stored in "monitor.properties" and
  1001. * are fairly self explanatory.
  1002. *
  1003. * @author Will Glozer
  1004. * @version 1.05a 09/06/2000
  1005. */
  1006. public class BuildMonitor implements BuildListener {
  1007. protected Properties props;
  1008. /**
  1009. * Create a new BuildMonitor.
  1010. */
  1011. public BuildMonitor() throws Exception {
  1012. props = new Properties();
  1013. InputStream is = getClass().getResourceAsStream("monitor.properties");
  1014. props.load(is);
  1015. is.close();
  1016. }
  1017. public void buildStarted(BuildEvent e) {
  1018. }
  1019. /**
  1020. * Determine the status of the build and the actions to follow, now that
  1021. * the build has completed.
  1022. *
  1023. * @param e Event describing the build status.
  1024. */
  1025. public void buildFinished(BuildEvent e) {
  1026. Throwable th = e.getException();
  1027. String status = (th != null) ? "failed" : "succeeded";
  1028. try {
  1029. String key = "build." + status;
  1030. if (props.getProperty(key + ".notify").equalsIgnoreCase("false")) {
  1031. return;
  1032. }
  1033. Session session = Session.getDefaultInstance(props, null);
  1034. MimeMessage message = new MimeMessage(session);
  1035. message.addRecipients(Message.RecipientType.TO, parseAddresses(
  1036. props.getProperty(key + ".email.to")));
  1037. message.setSubject(props.getProperty(key + ".email.subject"));
  1038. BufferedReader br = new BufferedReader(new FileReader(
  1039. props.getProperty("build.log")));
  1040. StringWriter sw = new StringWriter();
  1041. String line = br.readLine();
  1042. while (line != null) {
  1043. sw.write(line);
  1044. sw.write("\n");
  1045. line = br.readLine();
  1046. }
  1047. br.close();
  1048. message.setText(sw.toString(), "UTF-8");
  1049. sw.close();
  1050. Transport transport = session.getTransport();
  1051. transport.connect();
  1052. transport.send(message);
  1053. transport.close();
  1054. } catch (Exception ex) {
  1055. System.out.println("BuildMonitor failed to send email!");
  1056. ex.printStackTrace();
  1057. }
  1058. }
  1059. /**
  1060. * Parse a comma separated list of internet email addresses.
  1061. *
  1062. * @param s The list of addresses.
  1063. * @return Array of Addresses.
  1064. */
  1065. protected Address[] parseAddresses(String s) throws Exception {
  1066. StringTokenizer st = new StringTokenizer(s, ",");
  1067. Address[] addrs = new Address[st.countTokens()];
  1068. for (int i = 0; i < addrs.length; i++) {
  1069. addrs[i] = new InternetAddress(st.nextToken());
  1070. }
  1071. return addrs;
  1072. }
  1073. public void messageLogged(BuildEvent e) {
  1074. }
  1075. public void targetStarted(BuildEvent e) {
  1076. }
  1077. public void targetFinished(BuildEvent e) {
  1078. }
  1079. public void taskStarted(BuildEvent e) {
  1080. }
  1081. public void taskFinished(BuildEvent e) {
  1082. }
  1083. }
  1084. ]]></source>
  1085. <p>With a <code>monitor.properties</code> like this:</p>
  1086. <source><![CDATA[
  1087. # configuration for build monitor
  1088. mail.transport.protocol=smtp
  1089. mail.smtp.host=<host>
  1090. mail.from=Will Glozer <will.glozer@jda.com>
  1091. build.log=build.log
  1092. build.failed.notify=true
  1093. build.failed.email.to=will.glozer@jda.com
  1094. build.failed.email.subject=Nightly build failed!
  1095. build.succeeded.notify=true
  1096. build.succeeded.email.to=will.glozer@jda.com
  1097. build.succeeded.email.subject=Nightly build succeeded!
  1098. ]]></source>
  1099. <p><code>monitor.properties</code> should be placed right next
  1100. to your compiled <code>BuildMonitor.class</code>. To use it,
  1101. invoke Ant like:</p>
  1102. <source><![CDATA[
  1103. ant -listener BuildMonitor -logfile build.log
  1104. ]]></source>
  1105. <p>Make sure that <code>mail.jar</code> from JavaMail and
  1106. <code>activation.jar</code> from the
  1107. <a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java
  1108. Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p>
  1109. </answer>
  1110. </faq>
  1111. <faq id="listener-properties">
  1112. <question>How do I get at the properties that Ant was running
  1113. with from inside BuildListener?</question>
  1114. <answer>
  1115. <p>You can get at a hashtable with all the properties that Ant
  1116. has been using through the BuildEvent parameter. For
  1117. example:</p>
  1118. <source><![CDATA[
  1119. public void buildFinished(BuildEvent e) {
  1120. Hashtable table = e.getProject().getProperties();
  1121. String buildpath = (String)table.get("build.path");
  1122. ...
  1123. }
  1124. ]]></source>
  1125. <p>This is more accurate than just reading the same property
  1126. files that your project does, since it will give the correct
  1127. results for properties that were specified on the Ant command line.</p>
  1128. </answer>
  1129. </faq>
  1130. </faqsection>
  1131. <faqsection title="Known Problems">
  1132. <faq id="input-makes-exec-hang">
  1133. <question><code>&lt;exec&gt;</code> causes other tasks to hang
  1134. or leads to strange behaviour of <code>&lt;input&gt;</code>
  1135. tasks.</question>
  1136. <answer>
  1137. <p>When Ant forks a new process for example by using the
  1138. <code>&lt;exec&gt;</code>, <code>&lt;apply&gt;</code>
  1139. or <code>&lt;java&gt;</code> tasks, it will also start a
  1140. new thread reading from standard input and sending
  1141. everything that it has read to that process.</p>
  1142. <p>Unfortunately Ant has no way to know whether the forked
  1143. process is ever going to read any input, so it will start such
  1144. a thread even if the process doesn't need one.</p>
  1145. <p>This behaviour leads to strange side effects like the Ant
  1146. process being suspended when a build forking new process is
  1147. run as a background process on Unix-like systems or
  1148. <code>&lt;input&gt;</code> tasks requiring additional inputs
  1149. if they come after an <code>&lt;exec&gt;</code> task.</p>
  1150. <p>Fortunately there is a workaround for this, always specify
  1151. <code>inputstring=""</code> for
  1152. any <code>&lt;exec&gt;</code> task (or one of its sibblings)
  1153. if you know the forked process doesn't consume any
  1154. input.</p>
  1155. </answer>
  1156. </faq>
  1157. <faq id="170-requires-junit">
  1158. <question>Ant 1.7.0 doesn't build from sources without
  1159. JUnit</question>
  1160. <answer>
  1161. <p>When building Ant 1.7.0 from the source release without
  1162. junit.jar the build fails with the message "We cannot build
  1163. the test jar unless JUnit is present".</p>
  1164. <p>With Ant 1.7.0 we've started to add ant-testutil.jar as
  1165. part of the distribution and this causes a hard dependency on
  1166. JUnit - at least in version 1.7.0. Unfortunately the
  1167. installation docs don't say so.</p>
  1168. <p>There are two workarounds:</p>
  1169. <ol>
  1170. <li>Add junit.jar to your CLASSPATH when building Ant.</li>
  1171. <li>Change Ant's buildfile and remove test-jar from the
  1172. depends list of the dist-lite target.</li>
  1173. </ol>
  1174. </answer>
  1175. </faq>
  1176. <faq id="remove-cr">
  1177. <question>&lt;chmod&gt; or &lt;exec&gt; doesn&apos;t work in Ant
  1178. 1.3 on Unix</question>
  1179. <answer>
  1180. <p>The <code>antRun</code> script in <code>ANT_HOME/bin</code>
  1181. has DOS instead of Unix line endings; you must remove the
  1182. carriage-return characters from this file. This can be done by
  1183. using Ant&apos;s <code>&lt;fixcrlf&gt;</code> task
  1184. or something like:</p>
  1185. <source><![CDATA[
  1186. tr -d '\r' < $ANT_HOME/bin/antRun > /tmp/foo
  1187. mv /tmp/foo $ANT_HOME/bin/antRun
  1188. ]]></source>
  1189. </answer>
  1190. </faq>
  1191. <faq id="javadoc-cannot-execute">
  1192. <question>JavaDoc failed: java.io.IOException: javadoc: cannot execute</question>
  1193. <answer>
  1194. <p>There is a bug in the Solaris reference implementation of
  1195. 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>).
  1196. This also appears to be true under Linux. Moving the JDK to
  1197. the front of the PATH fixes the problem.</p>
  1198. </answer>
  1199. </faq>
  1200. <faq id="delegating-classloader">
  1201. <question>&lt;style&gt; or &lt;junit&gt; ignores my
  1202. &lt;classpath&gt;</question>
  1203. <answer>
  1204. <p>Starting with Ant 1.7.0, &lt;junit&gt; will honor your
  1205. nested &lt;classpath&gt;.</p>
  1206. <p>These tasks don&apos;t ignore your classpath setting, you
  1207. are facing a common problem with delegating classloaders.</p>
  1208. <p>This question collects a common type of problem: A task
  1209. needs an external library and it has a nested classpath
  1210. element so that you can point it to this external library, but
  1211. that doesn&apos;t work unless you put the external library
  1212. into the <code>CLASSPATH</code> or place it in
  1213. <code>ANT_HOME/lib</code>.</p>
  1214. <p>Some background is necessary before we can discuss
  1215. solutions for <a href="#delegating-classloader-1.5">Ant
  1216. 1.5.x</a> and <a href="#delegating-classloader-1.6">Ant
  1217. 1.6.x</a>.</p>
  1218. <p>When you specify a nested <code>&lt;classpath&gt;</code> in
  1219. Ant, Ant creates a new class loader that uses the path you
  1220. have specified. It then tries to load additional classes from
  1221. this classloader.</p>
  1222. <p>In most cases - for example using &lt;style&gt; or
  1223. &lt;junit&gt; - Ant doesn&apos;t load the external library
  1224. directly, it is the loaded class that does so.</p>
  1225. <p>In the case of <code>&lt;junit&gt;</code> it is the task
  1226. implementation itself and in the case of
  1227. <code>&lt;style&gt;</code> it is the implementation of the
  1228. <code>org.apache.tools.ant.taskdefs.XSLTLiaison</code>
  1229. class.</p>
  1230. <p><em>As of Ant 1.7</em> <code>&lt;junit&gt;</code> no longer
  1231. requires you to have <code>junit.jar</code> in Ant's startup
  1232. classpath even if <code>ant-junit.jar</code> is present there.</p>
  1233. <p>Ant&apos;s class loader implementation uses Java&apos;s
  1234. delegation model, see <a
  1235. 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>
  1236. the paragraph</p>
  1237. <blockquote>The <code>ClassLoader</code> class uses a
  1238. delegation model to search for classes and resources. Each
  1239. instance of <code>ClassLoader</code> has an associated parent
  1240. class loader. When called upon to find a class or resource, a
  1241. <code>ClassLoader</code> instance will delegate the search for
  1242. the class or resource to its parent class loader before
  1243. attempting to find the class or resource itself. The virtual
  1244. machine&apos;s built-in class loader, called the bootstrap
  1245. class loader, does not itself have a parent but may serve as
  1246. the parent of a <code>ClassLoader</code>
  1247. instance.</blockquote>
  1248. <p>The possible solutions depend on the version of Ant you
  1249. use, see the next sections.</p>
  1250. </answer>
  1251. </faq>
  1252. <faq id="delegating-classloader-1.5">
  1253. <question>&lt;style&gt; or &lt;junit&gt; ignores my
  1254. &lt;classpath&gt; - Ant 1.5.x version</question>
  1255. <answer>
  1256. <p>Please read <a href="#delegating-classloader">the previous
  1257. entry</a> before you go ahead.</p>
  1258. <p>First of all let&apos;s state that Ant's wrapper script
  1259. (<code>ant</code> or <code>ant.bat</code>) adds all
  1260. <code>.jar</code> files from <code>ANT_HOME/lib</code> to
  1261. <code>CLASSPATH</code>, therefore &quot;in
  1262. <code>CLASSPATH</code>&quot; shall mean &quot;either in your
  1263. <code>CLASSPATH</code> environment variable or
  1264. <code>ANT_HOME/lib</code>&quot; for the rest of this
  1265. answer.</p>
  1266. <p>The root of the problem is that the class that needs the
  1267. external library is on the <code>CLASSPATH</code>.</p>
  1268. <p>Let's see what happens when you load the &lt;junit&gt;
  1269. task. Ant&apos;s class loader will consult the
  1270. bootstrap class loader first, which tries to load classes from
  1271. <code>CLASSPATH</code>. The bootstrap class loader
  1272. doesn&apos;t know anything about Ant&apos;s class loader or
  1273. even the path you have specified.</p>
  1274. <p>If the bootstrap class loader can load the class Ant has
  1275. asked it to load (which it can if <code>optional.jar</code> is
  1276. part of <code>CLASSPATH</code>), this class will try to load
  1277. the external library from <code>CLASSPATH</code> as well - it
  1278. doesn&apos;t know anything else - and will not find it unless
  1279. the library is in <code>CLASSPATH</code> as well.</p>
  1280. <p>To solve this, you have two major options:</p>
  1281. <ol>
  1282. <li>put all external libraries you need in
  1283. <code>CLASSPATH</code> as well this is not what you want,
  1284. otherwise you wouldn&apos;t have found this FAQ entry.</li>
  1285. <li>remove the class that loads the external library from
  1286. the <code>CLASSPATH</code>.</li>
  1287. </ol>
  1288. <p>The easiest way to do this is to remove
  1289. <code>optional.jar</code> from <code>ANT_HOME/lib</code>. If
  1290. you do so, you will have to <code>&lt;taskdef&gt;</code> all
  1291. optional tasks and use nested <code>&lt;classpath&gt;</code>
  1292. elements in the <code>&lt;taskdef&gt;</code> tasks that point
  1293. to the new location of <code>optional.jar</code>. Also,
  1294. don&apos;t forget to add the new location of
  1295. <code>optional.jar</code> to the
  1296. <code>&lt;classpath&gt;</code> of your
  1297. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code>
  1298. task.</p>
  1299. <p>If you want to avoid to <code>&lt;taskdef&gt;</code> all
  1300. optional tasks you need, the only other option is to remove
  1301. the classes that should not be loaded via the bootstrap class
  1302. loader from <code>optional.jar</code> and put them into a
  1303. separate archive. Add this separate archive to the
  1304. <code>&lt;classpath&gt;</code> of your
  1305. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code> task
  1306. - and make sure the separate archive is not in
  1307. <code>CLASSPATH</code>.</p>
  1308. <p>In the case of <code>&lt;junit&gt;</code> you&apos;d have
  1309. to remove all classes that are in the
  1310. <code>org/apache/tools/ant/taskdefs/optional/junit</code>
  1311. directory, in the <code>&lt;style&gt;</code> case it is one of
  1312. the <code>*Liaison</code> classes in
  1313. <code>org/apache/tools/ant/taskdefs/optional</code>.</p>
  1314. <p>If you use the option to break up <code>optional.jar</code>
  1315. for <code>&lt;junit&gt;</code> or remove
  1316. <code>ant-junit.jar</code>, you still have to use a
  1317. <code>&lt;taskdef&gt;</code> with a nested
  1318. <code>&lt;classpath&gt;</code> to define the junit task.</p>
  1319. </answer>
  1320. </faq>
  1321. <faq id="delegating-classloader-1.6">
  1322. <question>&lt;style&gt; or &lt;junit&gt; ignores my
  1323. &lt;classpath&gt; - Ant 1.6.x version</question>
  1324. <answer>
  1325. <p>Please read <a href="#delegating-classloader">the general
  1326. entry</a> before you go ahead.</p>
  1327. <p>The wrapper script of Ant 1.6.x no longer adds the contents
  1328. of <code>ANT_HOME/lib</code> to <code>CLASSPATH</code>,
  1329. instead Ant will create a classloader on top of the bootstrap
  1330. classloader - let's call it the coreloader for the rest of
  1331. this answer - which holds the contents of
  1332. <code>ANT_HOME/lib</code>. Ant's core and its tasks will be
  1333. loaded through this classloader and not the bootstrap
  1334. classloader.</p>
  1335. <p>This causes some small but notable differences between Ant
  1336. 1.5.x and 1.6.x. Most importantly, a third-party task that is
  1337. part of <code>CLASSPATH</code> will no longer work in Ant
  1338. 1.6.x since the task now can't find Ant's classes. In a sense
  1339. this is the same problem this entry is about, only
  1340. <code>ant.jar</code> has become the external library in
  1341. question now.</p>
  1342. <p>This coreloader also holds the contents of
  1343. <code>~/.ant/lib</code> and any file or directory that has
  1344. been specified using Ant's <code>-lib</code> command line
  1345. argument.</p>
  1346. <p>Let's see what happens when you load the &lt;junit&gt;
  1347. task. Ant&apos;s class loader will consult the bootstrap
  1348. class loader first, which tries to load classes from
  1349. <code>CLASSPATH</code>. The bootstrap class loader
  1350. doesn&apos;t know anything about Ant&apos;s class loader or
  1351. even the path you have specified. If it fails to find the
  1352. class using the bootstrap classloader it will try the
  1353. coreloader next. Again, the coreloader doesn't know anything
  1354. about your path.</p>
  1355. <p>If the coreloader can load the class Ant has asked it to
  1356. load (which it can if <code>ant-junit.jar</code> is in
  1357. <code>ANT_HOME/lib</code>), this class will try to load the
  1358. external library from coreloader as well - it doesn&apos;t
  1359. know anything else - and will not find it unless the library
  1360. is in <code>CLASSPATH</code> or the coreloader as well.</p>
  1361. <p>To solve this, you have the following major options:</p>
  1362. <ol>
  1363. <li>put all external libraries you need in
  1364. <code>CLASSPATH</code> as well this is not what you want,
  1365. otherwise you wouldn&apos;t have found this FAQ entry.</li>
  1366. <li>put all external libraries you need in
  1367. <code>ANT_HOME/lib</code> or <code>.ant/lib</code>. This
  1368. probably still isn't what you want, but you might reconsider
  1369. the <code>.ant/lib</code> option.</li>
  1370. <li>Always start Ant with the <code>-lib</code> command line
  1371. switch and point to your external libraries (or the
  1372. directories holding them).</li>
  1373. <li>remove the class that loads the external library from
  1374. the coreloader.</li>
  1375. </ol>
  1376. <p>In Ant 1.6 <code>optional.jar</code> has been split into
  1377. multiple jars, each one containing classes with the same
  1378. dependencies on external libraries. You can move the
  1379. "offending" jar out of <code>ANT_HOME/lib</code>. For the
  1380. <code>&lt;junit&gt;</code> task it would be
  1381. <code>ant-junit.jar</code> and for <code>&lt;style&gt;</code>
  1382. it would be <code>ant-trax.jar</code>
  1383. or <code>ant-xslp.jar</code> -
  1384. depending on the processor you use.</p>
  1385. <p>If you do so, you will have to <code>&lt;taskdef&gt;</code>
  1386. all optional tasks that need the external library and use
  1387. nested <code>&lt;classpath&gt;</code> elements in the
  1388. <code>&lt;taskdef&gt;</code> tasks that point to the new
  1389. location of <code>ant-*.jar</code>. Also, don&apos;t forget
  1390. to add the new location of <code>ant-*.jar</code> to the
  1391. <code>&lt;classpath&gt;</code> of your
  1392. <code>&lt;style&gt;</code> or <code>&lt;junit&gt;</code>
  1393. task.</p>
  1394. <p>For example</p>
  1395. <source><![CDATA[
  1396. <taskdef name="junit"
  1397. class="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
  1398. <classpath>
  1399. <pathelement location="HOME-OF/junit.jar"/>
  1400. <pathelement location="NEW-HOME-OF/ant-junit.jar"/>
  1401. </classpath>
  1402. </taskdef>
  1403. ]]></source>
  1404. </answer>
  1405. </faq>
  1406. <faq id="winxp-jdk14-ant14">
  1407. <question>When running Ant 1.4 on Windows XP and JDK 1.4, I get
  1408. various errors when trying to <code>&lt;exec&gt;</code>, fork
  1409. <code>&lt;java&gt;</code> or access environment
  1410. variables.</question>
  1411. <answer>
  1412. <p>Ant &lt; 1.5 doesn&apos;t recognize Windows XP as a flavor
  1413. of Windows that runs <code>CMD.EXE</code> instead of
  1414. <code>COMMAND.COM</code>. JDK 1.3 will tell Ant that Windows
  1415. XP is Windows 2000 so the problem doesn&apos;t show up
  1416. there.</p>
  1417. <p>Apart from upgrading to Ant 1.5 or better, setting the
  1418. environment variable <code>ANT_OPTS</code> to
  1419. <code>-Dos.name=Windows_NT</code> prior to invoking Ant has
  1420. been confirmed as a workaround.</p>
  1421. </answer>
  1422. </faq>
  1423. <faq id="1.5-cygwin-sh">
  1424. <question>The <code>ant</code> wrapper script of Ant 1.5 fails
  1425. for Cygwin if <code>ANT_HOME</code> is set to a Windows style
  1426. path.</question>
  1427. <answer>
  1428. <p>This problem has been reported only hours after Ant 1.5 has
  1429. been released, see <a
  1430. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=10664">Bug
  1431. 10664</a> and all its duplicates.</p>
  1432. <p>A fixed version of the wrapper script can be found <a
  1433. href="http://ant.apache.org/old-releases/v1.5/errata/">here</a>.
  1434. Simply replace your script with this version.</p>
  1435. </answer>
  1436. </faq>
  1437. <faq id="1.5.2-zip-broken">
  1438. <question><code>&lt;zip&gt;</code> is broken in Ant 1.5.2.</question>
  1439. <answer>
  1440. <p>Yes, it is.</p>
  1441. <p>The problem reported by most people - see <a
  1442. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17648">Bug
  1443. 17648</a> and all its duplicates - is that Ant creates
  1444. archives that a partially unreadable by WinZIP. Luckily
  1445. <code>jar</code> deals with the archives and so the generated
  1446. jars/wars/ears will most likely work for you anyway.</p>
  1447. <p>There are additional problems, see bugs <a
  1448. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17780">Bug
  1449. 17780</a>, <a
  1450. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=17871">Bug
  1451. 17871</a> and <a
  1452. href="http://issues.apache.org/bugzilla/show_bug.cgi?id=18403">Bug
  1453. 18403</a>. All of them are supposed to be fixed with Ant
  1454. 1.5.3 (and only 18403 should exist in 1.5.3beta1).</p>
  1455. </answer>
  1456. </faq>
  1457. <faq id="unknownelement.taskcontainer">
  1458. <question>
  1459. Why do my custom task containers see Unknown Elements in Ant 1.6
  1460. - they worked in Ant 1.5?
  1461. </question>
  1462. <answer>
  1463. <p>
  1464. The objects added in TaskContainer.addTask(Task task)
  1465. have changed from Tasks to UnknownElements.
  1466. </p>
  1467. <p>
  1468. There was a number of valid reasons for this change. But the backward
  1469. compatibility problems were not noticed until after Ant 1.6.0 was
  1470. released.
  1471. </p>
  1472. <p>
  1473. Your container class will need to be modified to check if the Task
  1474. is an UnknownElement and call perform on it to
  1475. convert it to a Task and to execute it.
  1476. (see apache.tools.ant.taskdefs.Sequential)
  1477. </p>
  1478. <p>
  1479. If you want to do more processing on the task,
  1480. you need to use the techniques in apache.tools.ant.taskdefs.Antlib#execute()
  1481. This does make use of one 1.6 method call (UE#getRealObject()),
  1482. you need to use UE#getTask() instead - this will
  1483. return null for non tasks (types like fileset id=x).
  1484. </p>
  1485. <p>
  1486. So.. iterate over the tasks, if they are UEs, convert them to
  1487. tasks, using UE#maybeConfigure and UE#getTask()
  1488. </p>
  1489. <source><![CDATA[
  1490. for (Iterator i = tasks.iterator(); i.hasNext();) {
  1491. Task t = (Task) i.next();
  1492. if (t instanceof UnknownElement) {
  1493. ((UnknownElement) t).maybeConfigure();
  1494. t = ((UnknownElement) t).getTask();
  1495. if (t == null) {
  1496. continue;
  1497. }
  1498. }
  1499. // .... original Custom code
  1500. }
  1501. ]]></source>
  1502. <p>
  1503. This approach should work for ant1.5 and ant1.6.
  1504. </p>
  1505. </answer>
  1506. </faq>
  1507. <faq id="java.exception.stacktrace">
  1508. <question>
  1509. The program I run via &lt;java&gt; throws an exception but I
  1510. can't seem to get the full stack trace.
  1511. </question>
  1512. <answer>
  1513. <p>This is a know bug that has been fixed after the release of
  1514. Ant 1.6.1.</p>
  1515. <p>As a workaround, run your &lt;java&gt; task with
  1516. <code>fork="true"</code> and Ant will display the full
  1517. trace.</p>
  1518. </answer>
  1519. </faq>
  1520. <faq id="junit-no-runtime-xml">
  1521. <question>
  1522. Using format=&quot;xml&quot;, &lt;junit&gt; fails with a
  1523. <code>NoClassDefFoundError</code> if forked.
  1524. </question>
  1525. <answer>
  1526. <p>The XML formatter needs the <a
  1527. href="http://www.w3.org/DOM/">DOM classes</a> to work. If you
  1528. are using JDK 1.4 or later they are included with your Java
  1529. Runtime and this problem won't occur. If you are running JDK
  1530. 1.3 or earlier, the DOM classes have to be on your
  1531. &lt;junit&gt; task's &lt;classpath&gt;.</p>
  1532. <p>Prior to Ant 1.6.0 Ant would include the DOM classes from
  1533. the XML parser that is used by Ant itself if you set the
  1534. includeAntRuntime attribute to true (the default). With Ant
  1535. 1.6.0 this has been changed as this behavior made it
  1536. impossible to use a different XML parser in your tests.</p>
  1537. <p>This means that you have to take care of the DOM classes
  1538. explicitly starting with Ant 1.6.0. If you don't need to set
  1539. up a different XML parser for your tests, the easiest solution
  1540. is to add</p>
  1541. <source><![CDATA[
  1542. <pathelement path="${ant.home}/lib/xml-apis.jar:${ant.home}/lib/xercesImpl.jar"/>
  1543. ]]></source>
  1544. <p>to your task's &lt;classpath&gt;.</p>
  1545. </answer>
  1546. </faq>
  1547. <faq id="xalan-jdk1.5">
  1548. <question>
  1549. <code>&lt;junitreport&gt;</code> doesn't work with JDK 1.5 but
  1550. worked fine with JDK 1.4.
  1551. </question>
  1552. <answer>
  1553. <p>While JDK 1.4.x contains a version of Xalan-J 2, JDK 1.5
  1554. (and later?) have <a
  1555. href="http://java.sun.com/j2se/1.5.0/compatibility.html#4959783">moved
  1556. to XSLTC</a>. Since this task uses Xalan's redirect
  1557. extensions for its internal stylesheet, Ant prior to 1.6.2 didn't support
  1558. XSLTC. This means that you have to install <a
  1559. href="http://xml.apache.org/xalan-j/">Xalan-J 2</a> in order
  1560. to use this task with JDK 1.5 in older versions of Ant.</p>
  1561. <p>Starting with Ant 1.6.2 <code>&lt;junitreport&gt;</code>
  1562. supports JDK 1.5.</p>
  1563. </answer>
  1564. </faq>
  1565. </faqsection>
  1566. </document>