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

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