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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <?xml version="1.0"?>
  2. <document>
  3. <properties>
  4. <author email="bodewig@apache.org">Stefan Bodewig</author>
  5. <title>Frequently Asked Questions</title>
  6. </properties>
  7. <faqsection title="General">
  8. <faq id="what-is-ant">
  9. <question>What is Ant?</question>
  10. <answer>
  11. <p> Ant is a Java based build tool. In theory it is kind of
  12. like &quot;make&quot; without makes wrinkles and with the full
  13. portability of pure Java code.</p>
  14. </answer>
  15. </faq>
  16. <faq id="ant-name">
  17. <question>Why do you call it Ant?</question>
  18. <answer>
  19. <p>According to Ant&apos;s original author James Duncan
  20. Davidson, the name is an acronym for &quot;Another Neat
  21. Tool&quot;.</p>
  22. <p>Later explanations go along the lines of &quot;Ants are
  23. doing an extremely good job at building things&quot; or
  24. &quot;Ants are very small and can carry a weight a dozen times
  25. of their own&quot; - describing what Ant is intended to
  26. be.</p>
  27. </answer>
  28. </faq>
  29. <faq id="history">
  30. <question>Tell us a little bit about Ant&apos;s history.</question>
  31. <answer>
  32. <p>Initially Ant was part of the Tomcat code base when it was
  33. donated to the Apache Software Foundation - it has been
  34. created by James Duncan Davidson, who also is the original
  35. author of Tomcat. Ant was there to build Tomcat, nothing
  36. else.</p>
  37. <p>Soon thereafter several open source Java projects realized
  38. that Ant could solve the problems they had with makefiles.
  39. Starting with the projects hosted at Jakarta and the old Java
  40. Apache project, Ant spread like a virus and now is the build
  41. tool of choice for a lot of projects.</p>
  42. <p>In January 2000 Ant was moved to a separate CVS module and
  43. was promoted to a project of its own, independent of
  44. Tomcat.</p>
  45. <p>The first version of Ant that was exposed a lager audience
  46. was the one that shipped with Tomcat's 3.1 release on 19 April
  47. 2000. This version has later been referenced to as Ant
  48. 0.3.1.</p>
  49. <p>The first official release of Ant as a stand alone product was
  50. Ant 1.1 released on 19 July 2000. The complete release
  51. history:</p>
  52. <table>
  53. <tr>
  54. <th>Ant Version</th>
  55. <th>Release Date</th>
  56. </tr>
  57. <tr>
  58. <td>1.1</td>
  59. <td>19 July 2000</td>
  60. </tr>
  61. <tr>
  62. <td>1.2</td>
  63. <td>24 October 2000</td>
  64. </tr>
  65. <tr>
  66. <td>1.3</td>
  67. <td>3 March 2001</td>
  68. </tr>
  69. </table>
  70. </answer>
  71. </faq>
  72. </faqsection>
  73. <faqsection title="Installation">
  74. <faq id="no-gnu-tar">
  75. <question>I get checksum errors when I try to extract the
  76. <code>tar.gz</code> distribution file. Why?</question>
  77. <answer>
  78. <p>Ant&apos;s distribution contains file names that are longer
  79. than 100 characters, which is not supported by the standard
  80. tar file format. Several different implementations of tar use
  81. different and incompatible ways to work around this
  82. restriction.</p>
  83. <p>Ant&apos;s &lt;tar&gt; task can create tar archives that use
  84. the GNU tar extension, and this has been used when putting
  85. together the distribution. If you are using a different
  86. version of tar (for example, the one shipping with Solaris),
  87. you cannot use it to extract the archive.</p>
  88. <p>The solution is to either install GNU tar, which can be
  89. found <a href="http://www.gnu.org/software/tar/tar.html">here</a>
  90. or use the zip archive instead (you can extract it using
  91. <code>jar xf</code>).</p>
  92. </answer>
  93. </faq>
  94. </faqsection>
  95. <faqsection title="Ant and IDEs/Editors">
  96. <faq id="integration">
  97. <question>Is Ant supported by my IDE/Editor?</question>
  98. <answer>
  99. <p>See the <a href="external.html#IDE%47Editor+Integration">section
  100. on IDE integration</a> on our external tools page.</p>
  101. </answer>
  102. </faq>
  103. <faq id="emacs-mode">
  104. <question>Why doesn't (X)Emacs parse the error messages generated
  105. by Ant correctly?</question>
  106. <answer>
  107. <p>Ant adds a &quot;banner&quot; with the name of the current
  108. task in front of all messages - and there are no built-in
  109. regular expressions in Emacs that would account for this.</p>
  110. <p>You can disable this banner by invoking Ant with the
  111. <code>-emacs</code> switch. Alternatively you can add the
  112. following snippet to your <code>.emacs</code> to make Emacs
  113. understand Ant&apos;s output.</p>
  114. <source><![CDATA[
  115. (require 'compile)
  116. (setq compilation-error-regexp-alist
  117. (append (list
  118. ;; works for jikes
  119. '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3)
  120. ;; works for javac
  121. '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2))
  122. compilation-error-regexp-alist))
  123. ]]></source>
  124. </answer>
  125. </faq>
  126. </faqsection>
  127. <faqsection title="Advanced issues">
  128. <faq id="xml-entity-include">
  129. <question>How do I include an XML snippet in my build file?</question>
  130. <answer>
  131. <p>You can use XML&apos;s way of including external files and let
  132. the parser do the job for Ant:</p>
  133. <source><![CDATA[
  134. <?xml version="1.0"?>
  135. <!DOCTYPE project [
  136. <!ENTITY common SYSTEM "file:./common.xml">
  137. ]>
  138. <project name="test" default="test" basedir=".">
  139. <target name="setup">
  140. ...
  141. </target>
  142. &common;
  143. ...
  144. </project>
  145. ]]></source>
  146. <p>will literally include the contents of <code>common.xml</code> where
  147. you&apos;ve placed the <code>&amp;common;</code> entity.</p>
  148. <p>In combination with a DTD, this would look like this:</p>
  149. <source><![CDATA[
  150. <!DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "file:./ant.dtd" [
  151. <!ENTITY include SYSTEM "file:./header.xml">
  152. ]>
  153. ]]></source>
  154. </answer>
  155. </faq>
  156. <faq id="mail-logger">
  157. <question>How do I send an email with the result of my build
  158. process?</question>
  159. <answer>
  160. <p>You can use a custom BuildListener, that sends out an email
  161. in the buildFinished() method. Will Glozer
  162. &lt;will.glozer@jda.com&gt; has written such a listener based
  163. on JavaMail, the source is</p>
  164. <source><![CDATA[
  165. import java.io.*;
  166. import java.util.*;
  167. import javax.mail.*;
  168. import javax.mail.internet.*;
  169. import org.apache.tools.ant.*;
  170. /**
  171. * A simple listener that waits for a build to finish and sends an email
  172. * of the results. The settings are stored in "monitor.properties" and
  173. * are fairly self explanatory.
  174. *
  175. * @author Will Glozer
  176. * @version 1.05a 09/06/2000
  177. */
  178. public class BuildMonitor implements BuildListener {
  179. protected Properties props;
  180. /**
  181. * Create a new BuildMonitor.
  182. */
  183. public BuildMonitor() throws Exception {
  184. props = new Properties();
  185. InputStream is = getClass().getResourceAsStream("monitor.properties");
  186. props.load(is);
  187. is.close();
  188. }
  189. public void buildStarted(BuildEvent e) {
  190. }
  191. /**
  192. * Determine the status of the build and the actions to follow, now that
  193. * the build has completed.
  194. *
  195. * @param e Event describing the build tatus.
  196. */
  197. public void buildFinished(BuildEvent e) {
  198. Throwable th = e.getException();
  199. String status = (th != null) ? "failed" : "succeeded";
  200. try {
  201. String key = "build." + status;
  202. if (props.getProperty(key + ".notify").equalsIgnoreCase("false")) {
  203. return;
  204. }
  205. Session session = Session.getDefaultInstance(props, null);
  206. MimeMessage message = new MimeMessage(session);
  207. message.addRecipients(Message.RecipientType.TO, parseAddresses(
  208. props.getProperty(key + ".email.to")));
  209. message.setSubject(props.getProperty(key + ".email.subject"));
  210. BufferedReader br = new BufferedReader(new FileReader(
  211. props.getProperty("build.log")));
  212. StringWriter sw = new StringWriter();
  213. String line = br.readLine();
  214. while (line != null) {
  215. sw.write(line);
  216. sw.write("\n");
  217. line = br.readLine();
  218. }
  219. br.close();
  220. message.setText(sw.toString(), "UTF-8");
  221. sw.close();
  222. Transport transport = session.getTransport();
  223. transport.connect();
  224. transport.send(message);
  225. transport.close();
  226. } catch (Exception ex) {
  227. System.out.println("BuildMonitor failed to send email!");
  228. ex.printStackTrace();
  229. }
  230. }
  231. /**
  232. * Parse a comma separated list of internet email addresses.
  233. *
  234. * @param s The list of addresses.
  235. * @return Array of Addresses.
  236. */
  237. protected Address[] parseAddresses(String s) throws Exception {
  238. StringTokenizer st = new StringTokenizer(s, ",");
  239. Address[] addrs = new Address[st.countTokens()];
  240. for (int i = 0; i < addrs.length; i++) {
  241. addrs[i] = new InternetAddress(st.nextToken());
  242. }
  243. return addrs;
  244. }
  245. public void messageLogged(BuildEvent e) {
  246. }
  247. public void targetStarted(BuildEvent e) {
  248. }
  249. public void targetFinished(BuildEvent e) {
  250. }
  251. public void taskStarted(BuildEvent e) {
  252. }
  253. public void taskFinished(BuildEvent e) {
  254. }
  255. }
  256. ]]></source>
  257. <p>With a <code>monitor.properties</code> like this</p>
  258. <source><![CDATA[
  259. # configuration for build monitor
  260. mail.transport.protocol=smtp
  261. mail.smtp.host=<host>
  262. mail.from=Will Glozer <will.glozer@jda.com>
  263. build.log=build.log
  264. build.failed.notify=true
  265. build.failed.email.to=will.glozer@jda.com
  266. build.failed.email.subject=Nightly build failed!
  267. build.succeeded.notify=true
  268. build.succeeded.email.to=will.glozer@jda.com
  269. build.succeeded.email.subject=Nightly build succeeded!
  270. ]]></source>
  271. <p><code>monitor.properties</code> should be placed right next
  272. to your compiled <code>BuildMonitor.class</code>. To use it,
  273. invoke Ant like</p>
  274. <source><![CDATA[
  275. ant -listener BuildMonitor
  276. ]]></source>
  277. </answer>
  278. </faq>
  279. </faqsection>
  280. <faqsection title="Known problems">
  281. <faq id="remove-cr">
  282. <question>&lt;chmod&gt; or &lt;exec&gt; don&apos;t work in Ant
  283. 1.3 on Unix</question>
  284. <answer>
  285. <p>The <code>antRun</code> script in <code>ANT_HOME/bin</code>
  286. has DOS instead of Unix line endings, you must remove the
  287. carriage return characters from this file. This can be done by
  288. using Ant&apos;s &lt;fixcrlf&gt; task or something like:</p>
  289. <source><![CDATA[
  290. tr -d '\r' < $ANT_HOME/bin/antRun > /tmp/foo
  291. mv /tmp/foo $ANT_HOME/bin/antRun
  292. ]]></source>
  293. </answer>
  294. </faq>
  295. </faqsection>
  296. </document>