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

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