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

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