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

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