<?xml version="1.0"?>
<document>

  <properties>
    <author email="bodewig@apache.org">Stefan Bodewig</author>
    <title>Frequently Asked Questions</title>
  </properties>

  <faqsection title="About this FAQ">
    <faq id="latest-version">
      <question>Where do I find the latest version of this
        document?</question>
      <answer>
        <p>The latest version can always be found at Ant&apos;s homepage 
          <a href="http://jakarta.apache.org/ant/faq.html">http://jakarta.apache.org/ant/faq.html</a>.</p>
      </answer>
    </faq>

    <faq id="adding-faqs">
      <question>How can I contribute to this FAQ?</question>
      <answer>
        <p>The page you are looking it is generated from 
          <a href="http://cvs.apache.org/viewcvs.cgi/~checkout~/jakarta-ant/xdocs/faq.xml">this</a>
          document.  If you want to add a new question, please submit
          a patch against this document to one of Ant&apos;s mailing lists;
          hopefully, the structure is self-explanatory.</p>
        
        <p>If you don&apos;t know how to create a patch, see the patches
          section of <a href="http://jakarta.apache.org/site/source.html">this
          page</a>.</p>
      </answer>
    </faq>

    <faq id="creating-faq">
      <question>How do you create the HTML version of this
        FAQ?</question>

      <answer>
        <p>We use 
        <a href="http://jakarta.apache.org/velocity/anakia.html">Anakia</a>
        to render the HTML version from the original XML file.</p>

        <p>The Velocity stylesheets used to process the XML files can
        be found in the <code>xdocs/stylesheets</code> subdirectory of
        Ant&apos;s CVS repository - the build file <code>docs.xml</code> is
        used to drive Anakia.  This file assumes that you have the
        <code>jakarta-site2</code> module checked out from CVS as
        well, but if you follow the instruction from Anakia&apos;s
        homepage, you should get it to work without that.  Just make
        sure all required jars are in the task&apos;s classpath.</p>
      </answer>
    </faq>

  </faqsection>

  <faqsection title="General">
    <faq id="what-is-ant">
      <question>What is Apache Ant?</question>
      <answer>
        <p> Ant is a Java-based build tool. In theory, it is kind of
        like Make, without Make&apos;s wrinkles and with the full
        portability of pure Java code.</p>
      </answer>
    </faq>

    <faq id="ant-name">
      <question>Why do you call it Ant?</question>
      <answer>

        <p>According to Ant&apos;s original author, James Duncan
        Davidson, the name is an acronym for &quot;Another Neat
        Tool&quot;.</p>
        
        <p>Later explanations go along the lines of &quot;ants 
        do an extremely good job at building things&quot;, or
        &quot;ants are very small and can carry a weight dozens of times
        their own&quot; - describing what Ant is intended to
        be.</p>
      </answer>
    </faq>

    <faq id="history">
      <question>Tell us a little bit about Ant&apos;s history.</question>
      <answer>

        <p>Initially, Ant was part of the Tomcat code base, when it was
        donated to the Apache Software Foundation. It was
        created by James Duncan Davidson, who is also the original
        author of Tomcat. Ant was there to build Tomcat, nothing
        else.</p>

        <p>Soon thereafter, several open source Java projects realized
        that Ant could solve the problems they had with Makefiles.
        Starting with the projects hosted at Jakarta and the old Java
        Apache project, Ant spread like a virus and is now the build
        tool of choice for a lot of projects.</p>

        <p>In January 2000, Ant was moved to a separate CVS module and
        was promoted to a project of its own, independent of
        Tomcat, and became Apache Ant.</p>

        <p>The first version of Ant that was exposed to a larger audience
        was the one that shipped with Tomcat&apos;s 3.1 release on 19 April
        2000.  This version has later been referred to as Ant
        0.3.1.</p>

        <p>The first official release of Ant as a stand-alone product was
        Ant 1.1, released on 19 July 2000.  The complete release
        history:</p>

        <table>
          <tr>
            <th>Ant Version</th>
            <th>Release Date</th>
          </tr>

          <tr>
            <td>1.1</td>
            <td>19 July 2000</td>
          </tr>

          <tr>
            <td>1.2</td>
            <td>24 October 2000</td>
          </tr>

          <tr>
            <td>1.3</td>
            <td>3 March 2001</td>
          </tr>

          <tr>
            <td>1.4</td>
            <td>3 September 2001</td>
          </tr>

          <tr>
            <td>1.4.1</td>
            <td>11 October 2001</td>
          </tr>
        </table>
      </answer>
    </faq>

  </faqsection>

  <faqsection title="Installation">
    <faq id="no-gnu-tar">
      <question>I get checksum errors when I try to extract the
      <code>tar.gz</code> distribution file. Why?</question>
      <answer>
        <p>Ant&apos;s distribution contains file names that are longer
        than 100 characters, which is not supported by the standard
        tar file format. Several different implementations of tar use
        different and incompatible ways to work around this
        restriction.</p>

        <p>Ant&apos;s &lt;tar&gt; task can create tar archives that use
        the GNU tar extension, and this has been used when putting
        together the distribution. If you are using a different
        version of tar (for example, the one shipping with Solaris),
        you cannot use it to extract the archive.</p>

        <p>The solution is to either install GNU tar, which can be
        found <a href="http://www.gnu.org/software/tar/tar.html">here</a>,
        or use the zip archive instead (you can extract it using
        <code>jar xf</code>).</p>
      </answer>
    </faq>
  </faqsection>

  <faqsection title="Using Ant">
    <faq id="always-recompiles">
      <question>Why does Ant always recompile all my Java files?</question>
      <answer>

        <p>In order to find out which files should be compiled, Ant
        compares the timestamps of the source files to those of the
        resulting <code>.class</code> files.  Opening all source files
        to find out which package they belong to would be very
        inefficient. Instead, Ant expects you to place your
        source files in a directory hierarchy that mirrors your
        package hierarchy and to point Ant to the root of this
        directory tree with the <code>srcdir</code> attribute.</p>

        <p>Say you have <code>&lt;javac srcdir=&quot;src&quot;
        destdir=&quot;dest&quot;/&gt;</code>.  If Ant finds a file
        <code>src/a/b/C.java</code>, it expects it to be in package
        <code>a.b</code> so that the resulting <code>.class</code>
        file is going to be <code>dest/a/b/C.class</code>.</p>

        <p>If your source-tree directory structure does not match your
        package structure, Ant&apos;s heuristic won&apos;t work, and
        it will recompile classes that are up-to-date.  Ant is not the
        only tool that expects a source-tree layout like this.</p>

        <p>If you have Java source files that aren&apos;t declared to
        be part of any package, you can still use the <code>&lt;javac&gt;</code>
        task to compile these files correctly - just set the
        <code>srcdir</code> and <code>destdir</code> attributes to
        the actual directory the source
        files live in and the directory the class files should go into,
        respectively.</p>

      </answer>
    </faq>

    <faq id="passing-cli-args">
      <question>How do I pass parameters from the command line to my
        build file?</question>
      <answer>

        <p>Use properties. Using <code>ant
        -D<em>name</em>=<em>value</em></code> lets you define values for
        properties on the Ant command line. These properties can then be
        used within your build file as
        any normal property: <code>${<em>name</em>}</code> will put in
        <code><em>value</em></code>.</p>

      </answer>
    </faq>

    <faq id="jikes-switches">
      <question>How can I use Jikes-specific command-line
        switches?</question>

      <answer>

        <p>A couple of switches are supported via &quot;magic&quot;
          properties:</p>

        <table>
          <tr>
            <th>switch</th>
            <th>property</th>
            <th>default</th>
          </tr>

          <tr>
            <td>+E</td>
            <td>build.compiler.emacs</td>
            <td>false == not set</td>
          </tr>

          <tr>
            <td>+P</td>
            <td>build.compiler.pedantic</td>
            <td>false == not set</td>
          </tr>

          <tr>
            <td>+F</td>
            <td>build.compiler.fulldepend</td>
            <td>false == not set</td>
          </tr>

          <tr>
            <td><strong>(Only for Ant &lt; 1.4; replaced by the
                <code><strong>nowarn</strong></code>
                attribute of the <code><strong>&lt;javac&gt;</strong></code>
                task after that.)</strong><br></br>-nowarn</td>
            <td>build.compiler.warnings</td>
            <td>true == not set</td>
          </tr>

        </table>

      </answer>
    </faq>

    <faq id="shell-redirect-1">
      <question>How do I include a &lt; character in my command-line arguments?</question>
      <answer>
        <p>The short answer is "Use: <code>&amp;lt;</code>".</p>

        <p>The long answer is that this probably won&apos;t do what you
        want anyway (see <a href="#shell-redirect-2">the next
        section</a>).</p>
      </answer>
    </faq>

    <faq id="shell-redirect-2">
      <question>How do I redirect standard input or standard output
        in the <code>&lt;exec&gt;</code> task?</question>
      <answer>
        <p>Say you want to redirect the standard input stream of the
        <code>cat</code> command to read from a file, something
        like:</p>

        <source><![CDATA[
shell-prompt> cat < foo
]]></source>
        
        <p>and try to translate it into</p>

        <source><![CDATA[
<exec executable="cat">
  <arg value="&lt;" />
  <arg value="foo" />
</exec>
]]></source>

        <p>This will not do what you expect.  The input redirection is
        performed by your shell, not the command itself, so this
        should read:</p>
        
        <source><![CDATA[
<exec executable="/bin/sh">
  <arg value="-c" />
  <arg value="cat &lt; foo" />
</exec>
]]></source>

        <p>Note that you must use the <code>value</code> attribute of
        <code>&lt;arg&gt;</code> in the last element, in order to have
        the command passed as a single, quoted argument. Alternatively,
        you can use:</p>
        <source><![CDATA[
<exec executable="/bin/sh">
  <arg line='-c "cat &lt; foo"'/>
</exec>
]]></source>

        <p>Note the double-quotes nested inside the single-quotes.</p>

      </answer>
    </faq>

    <faq id="batch-shell-execute">
      <question>How do I execute a batch file or shell script from Ant?</question>
      <answer>

        <p>On native Unix systems, you should be able to run shell scripts
           directly. On systems running a Unix-type shell (for example, Cygwin
           on Windows) execute the (command) shell instead - <code>cmd</code>
           for batch files, <code>sh</code> for shell scripts - then pass the
           batch file or shell script (plus any arguments to the script)
           as a single command, using the <code>/c</code> or
           <code>-c</code> switch, respectively. See
           <a href="#shell-redirect-2">the above section</a>
           for example <code>&lt;exec&gt;</code> tasks
           executing <code>sh</code>. For batch files, use something like:</p>
        <source><![CDATA[
<exec dir="." executable="cmd" os="Windows NT">
  <arg line="/c test.bat"/>
</exec>
]]></source>

      </answer>
    </faq>

    <faq id="defaultexcludes">

      <question>I&apos;ve used a <code>&lt;delete&gt;</code> task to delete
      unwanted
      SourceSafe control files (CVS files, editor backup files, etc.), but
      it doesn&apos;t seem to work; the files never get deleted. What&apos;s
      wrong?</question>

      <answer>
        <p>This is probably happening because, by default, Ant excludes
        SourceSafe control files (<code>vssver.scc</code>) and certain other
        files from FileSets.</p>

        <p>Here&apos;s what you probably did:</p>


	<source><![CDATA[
<delete>
  <fileset dir="${build.src}" includes="**/vssver.scc"/>
</delete>
]]></source>

        <p>You need to switch off the default exclusions,
           and it will work:</p>
	<source><![CDATA[
<delete>
  <fileset dir="${build.src}" includes="**/vssver.scc"
           defaultexcludes="no"/>
</delete>
]]></source>
        
        <p>For a complete listing of the patterns that are excluded
        by default, see <a href="manual/dirtasks.html#defaultexcludes">the user
        manual</a>.</p>

      </answer>
    </faq>

    <faq id="multi-conditions">
      <question>I want to execute a particular target only if
        multiple conditions are true.</question>

      <answer>
        <p>There are actually several answers to this question.</p>

        <p>If you have only one set and one unset property to test,
        you can specify both an <code>if</code> and an <code>unless</code>
        attribute for the target, and they will act as if they
        are &quot;anded&quot; together.</p>

        <p>If you are using a version of Ant 1.3 or earlier, the
        way to work with all other cases is to chain targets together
        to determine the specific state you want to test for.</p>

        <p>To see how this works, assume you have three properties:
        <code>prop1</code>, <code>prop2</code>, and <code>prop3</code>.
        You want to test that <code>prop1</code> and <code>prop2</code> 
        are set, and that <code>prop3</code> is not. If the condition
        holds true you want to echo &quot;yes&quot;.</p>

        <p>Here is the implementation in Ant 1.3 and earlier:</p>

        <source><![CDATA[
<target name="cond" depends="cond-if"/>

<target name="cond-if" if="prop1">
  <antcall target="cond-if-2"/>
</target>

<target name="cond-if-2" if="prop2">
  <antcall target="cond-if-3"/>
</target>

<target name="cond-if-3" unless="prop3">
  <echo message="yes"/>
</target>
]]></source>

        <p>Note: <code>&lt;antcall&gt;</code> tasks do <em>not</em> pass
        property changes back up to the environment they were called
        from, so you would&apos;nt be able to, for example, set a
        <code>result</code> property in the <code>cond-if-3</code> target,
        then do
        <code>&lt;echo message=&quot;result is ${result}&quot;/&gt;</code>
        in the <code>cond</code> target.</p>

        <p>Starting with Ant 1.4, you can use the
        <code>&lt;condition&gt;</code> task.</p>

        <source><![CDATA[
<target name="cond" depends="cond-if,cond-else"/>

<target name="check-cond">
  <condition property="cond-is-true">
    <and>
      <not>
        <equals arg1="${prop1}" arg2="$${prop1}" />
      </not>
      <not>
        <equals arg1="${prop2}" arg2="$${prop2}" />
      </not>
      <equals arg1="${prop3}" arg2="$${prop3}" />
    </and>
  </condition>
</target>

<target name="cond-if" depends="check-cond" if="cond-is-true">
  <echo message="yes"/>
</target>

<target name="cond-else" depends="check-cond" unless="cond-is-true">
  <echo message="no"/>
</target>
]]></source>

        <p>This version takes advantage of two things:</p>

        <ul>
          <li>If a property <code>a</code> has not been set,
          <code>${a}</code> will evaluate to <code>${a}</code>.</li>

          <li>To get a literal <code>$</code> in Ant, you have to
          escape it with another <code>$</code> - this will also break
          the special treatment of the <code>${</code> sequence.</li>
        </ul>

        <p>Because testing for a literal <code>${property}</code> string
        isn&apos;t all that readable or easy to understand,
        post-1.4.1 Ant introduces the <code>&lt;isset&gt;</code> element 
	to the <code>&lt;condition&gt;</code> task.</p>

        <p>Here is the previous example done using
        <code>&lt;isset&gt;</code>:</p>

        <source><![CDATA[
<target name="check-cond">
  <condition property="cond-is-true">
    <and>
      <isset property="prop1"/>
      <isset property="prop2"/>
      <not>
        <isset property="prop3"/>
      </not>
    </and>
  </condition>
</target>
]]></source>

        <p>The last option is to use a scripting language to set the
        properties. This can be particularly handy when you need much
        finer control than the simple conditions shown here but, of
        course, comes with the overhead of adding JAR files to support
        the language, to say nothing of the added maintenance in requiring
        two languages to implement a single system. See the
        <a href="manual/OptionalTasks/script.html">
        <code>&lt;script&gt;</code> task documentation</a> for more
        details.</p>
      </answer>
    </faq>
    
    <faq id="stop-dependency">
      <question>I have a target I want to skip if a property is set,
      so I have <code>unless=&quot;property&quot;</code> as an attribute 
      of the target, but all the targets this target 
      depends on are still executed. Why?</question>

      <answer>
        <p>The list of dependencies is generated by Ant before any of the
        targets are run. This allows dependent targets, such as an 
        <code>init</code> target, to set properties that can control the 
       	execution of the targets higher in the dependency graph. This 
      	is a good thing.</p>

        <p>However, when your dependencies break down the
        higher-level task
        into several smaller steps, this behaviour becomes 
        counter-intuitive. There are a couple of solutions available:
        </p>

        <ol>
          <li>Put the same condition on each of the dependent targets.</li>
	  
          <li>Execute the steps using <code>&lt;antcall&gt;</code>,
          instead of specifying them inside the <code>depends</code>
          attribute.</li>
        </ol>
	
      </answer>
    </faq>
    
    <faq id="include-order">
      <question>In my <code>&lt;fileset&gt;</code>, I&apos;ve put in an
      <code>&lt;exclude&gt;</code> of all files followed by an
      <code>&lt;include&gt;</code> of just the files I want, but it
      isn&apos;t giving me any files at all. What&apos;s wrong?
      </question>

      <answer>
        <p>The order of the <code>&lt;include&gt;</code> and
        <code>&lt;exclude&gt;</code> tags within a <code>&lt;fileset&gt;</code>
        is ignored when the FileSet is created. Instead, all of the
        <code>&lt;include&gt;</code> elements are processed together,
        followed by all of the <code>&lt;exclude&gt;</code>
        elements. This means that the <code>&lt;exclude&gt;</code>
        elements only apply to the file list produced by the
        <code>&lt;include&gt;</code> elements.</p>

	<p>To get the files you want, focus on just the
	<code>&lt;include&gt;</code> patterns that would be necessary
	to get them. If you find you need to trim the list that the
  <code>&lt;include&gt;</code> elements
	produce, then use <code>&lt;exclude&gt;</code> elements.</p>
      </answer>
    </faq>
    
    <faq id="encoding">
      <question>How can I include national characters like German
        umlauts in my build file?</question>

      <answer>
        <p>You need to tell the XML parser which character encoding
        your build file uses, this is done inside the <a
        href="http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd">XML
        declaration</a>.</p>  

        <p>By default the parser assumes you are using the UTF-8
        encoding instead of your platform's default.  For most western
        european contries you should set the encoding to
        <code>ISO-8859-1</code>.  To do so, make the very first line
        of you build file read like</p>

        <source><![CDATA[
<?xml version="1.0" encoding="ISO-8859-1" ?>
]]></source>
      </answer>
    </faq>
  </faqsection>

  <faqsection title="Ant and IDEs/Editors">
    <faq id="integration">
      <question>Is Ant supported by my IDE/Editor?</question>
      <answer>
        <p>See the <a href="external.html#IDE and Editor Integration">section 
        on IDE integration</a> on our External Tools and Tasks page.</p>
      </answer>
    </faq>

    <faq id="emacs-mode">
      <question>Why doesn&apos;t (X)Emacs/vi/MacOS X&apos;s project builder
      correctly parse the error messages generated by Ant?</question>
      <answer>

        <p>Ant adds a &quot;banner&quot; with the name of the current
        task in front of all logging messages - and there are no built-in
        regular expressions in your editor that would account for
        this.</p>

        <p>You can disable this banner by invoking Ant with the
        <code>-emacs</code> switch. Alternatively, you can add the
        following snippet to your <code>.emacs</code> to make Emacs
        understand Ant&apos;s output.</p>

        <source><![CDATA[
(require 'compile)
(setq compilation-error-regexp-alist
  (append (list 
     ;; works for jikes
     '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3)
     ;; works for javac 
     '("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2))
  compilation-error-regexp-alist))
]]></source>

        <p>Yet another alternative that preserves most of Ant&apos;s
        formatting is to pipe Ant&apos;s output through the following Perl
        script by Dirk-Willem van Gulik:</p>

        <source><![CDATA[
#!/usr/bin/perl
#
# May 2001 dirkx@apache.org - remove any
# [foo] lines from the output; keeping
# spacing more or less there.
#
$|=1;
while(<STDIN>) {
	if (s/^(\s+)\[(\w+)\]//) {
		if ($2 ne $last) {
			print "$1\[$2\]";
			$s = ' ' x length($2);
		} else {
			print "$1 $s ";
		};
		$last = $2;
	};
	print;
};
]]></source>

      </answer>
    </faq>
  </faqsection>

  <faqsection title="Advanced Issues">
    <faq id="dtd">
      <question>Is there a DTD that I can use to validate my build
      files?</question>

      <answer>

        <p>An incomplete DTD can be created by the
          <code>&lt;antstructure&gt;</code> task - but this one
          has a few problems:</p>

          <ul>
            <li>It doesn&apos;t know about required attributes.  Only
            manual tweaking of this file can help here.</li>
          
            <li>It is not complete - if you add new tasks via
            <code>&lt;taskdef&gt;</code> it won&apos;t know about it.  See
            <a href="http://www.sdv.fr/pages/casa/html/ant-dtd.en.html">this
            page</a> by Michel Casabianca for a solution to this
            problem.  Note that the DTD you can download at this page
            is based on Ant 0.3.1.</li>

            <li>It may even be an invalid DTD.  As Ant allows tasks
            writers to define arbitrary elements, name collisions will
            happen quite frequently - if your version of Ant contains
            the optional <code>&lt;test&gt;</code> and
            <code>&lt;junit&gt;</code> tasks, there are two XML
            elements named <code>test</code> (the task and the nested child
            element of <code>&lt;junit&gt;</code>) with different attribute
            lists.  This problem cannot be solved; DTDs don&apos;t give a
            syntax rich enough to support this.</li>
          </ul>
      </answer>
    </faq>

    <faq id="xml-entity-include">
      <question>How do I include an XML snippet in my build file?</question>
      <answer>
        <p>You can use XML&apos;s way of including external files and let
        the parser do the job for Ant:</p>

        <source><![CDATA[
<?xml version="1.0"?>

<!DOCTYPE project [
    <!ENTITY common SYSTEM "file:./common.xml">
]>

<project name="test" default="test" basedir=".">

  <target name="setup">
    ...
  </target>

  &common;

  ...

</project>
]]></source>

        <p>will literally include the contents of <code>common.xml</code> where
        you&apos;ve placed the <code>&amp;common;</code> entity.</p>

        <p>In combination with a DTD, this would look like this:</p>

        <source><![CDATA[
<!DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "file:./ant.dtd" [
   <!ENTITY include SYSTEM "file:./header.xml">
]>
]]></source>
      </answer>
    </faq>

    <faq id="mail-logger">
      <question>How do I send an email with the result of my build
        process?</question>

      <answer>

        <p>If you are using a nightly build of Ant 1.5 after
        2001-12-14, you can use the built-in MailLogger:</p>

        <source><![CDATA[
         ant -logger org.apache.tools.ant.listener.MailLogger
]]></source>

        <p>See the <a href="http://cvs.apache.org/viewcvs/~checkout~/jakarta-ant/docs/manual/listeners.html?content-type=text/html">Listeners
        &amp; Loggers</a> documentation for details on the properties
        required.</p>

        <p>For older versions of Ant, you can use a custom
        BuildListener that sends out an email
        in the buildFinished() method.  Will Glozer
        &lt;will.glozer@jda.com&gt; has written such a listener based
        on <a href="http://java.sun.com/products/javamail/">JavaMail</a>. 
        The source is:</p>

        <source><![CDATA[
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import org.apache.tools.ant.*;

/**
 * A simple listener that waits for a build to finish and sends an email
 * of the results.  The settings are stored in "monitor.properties" and
 * are fairly self explanatory.
 *
 * @author      Will Glozer
 * @version     1.05a 09/06/2000
 */
public class BuildMonitor implements BuildListener {
    protected Properties props;

    /**
     * Create a new BuildMonitor.
     */
    public BuildMonitor() throws Exception {
        props = new Properties();
        InputStream is = getClass().getResourceAsStream("monitor.properties");
        props.load(is);
        is.close();
    }

    public void buildStarted(BuildEvent e) {
    }

    /**
     * Determine the status of the build and the actions to follow, now that
     * the build has completed.
     *
     * @param       e       Event describing the build tatus.
     */
    public void buildFinished(BuildEvent e) {
        Throwable th = e.getException();
        String status = (th != null) ? "failed" : "succeeded";
        
        try {
            String key = "build." + status;
            if (props.getProperty(key + ".notify").equalsIgnoreCase("false")) {
                    return;
            }
            
            Session session = Session.getDefaultInstance(props, null);

            MimeMessage message = new MimeMessage(session);
            message.addRecipients(Message.RecipientType.TO, parseAddresses(
                props.getProperty(key + ".email.to")));
            message.setSubject(props.getProperty(key + ".email.subject"));

            BufferedReader br = new BufferedReader(new FileReader(
                props.getProperty("build.log")));
            StringWriter sw = new StringWriter();
            
            String line = br.readLine();
            while (line != null) {
                sw.write(line);
                sw.write("\n");
                line = br.readLine();
            }
            br.close();
            
            message.setText(sw.toString(), "UTF-8");
            sw.close();
            
            Transport transport = session.getTransport();
            transport.connect();
            transport.send(message);
            transport.close();
        } catch (Exception ex) {
            System.out.println("BuildMonitor failed to send email!");
            ex.printStackTrace();
        }
    }

    /**
     * Parse a comma separated list of internet email addresses.
     *
     * @param       s       The list of addresses.
     * @return      Array of Addresses.
     */
    protected Address[] parseAddresses(String s) throws Exception {
        StringTokenizer st = new StringTokenizer(s, ",");
        Address[] addrs = new Address[st.countTokens()];

        for (int i = 0; i < addrs.length; i++) {
            addrs[i] = new InternetAddress(st.nextToken());
        }
        return addrs;
    }

    public void messageLogged(BuildEvent e) {
    }

    public void targetStarted(BuildEvent e) {
    }

    public void targetFinished(BuildEvent e) {
    }

    public void taskStarted(BuildEvent e) {        
    }

    public void taskFinished(BuildEvent e) {
    }
}
]]></source>
          
      <p>With a <code>monitor.properties</code> like this:</p>

        <source><![CDATA[
# configuration for build monitor

mail.transport.protocol=smtp
mail.smtp.host=<host>
mail.from=Will Glozer <will.glozer@jda.com>

build.log=build.log

build.failed.notify=true
build.failed.email.to=will.glozer@jda.com
build.failed.email.subject=Nightly build failed!

build.succeeded.notify=true
build.succeeded.email.to=will.glozer@jda.com
build.succeeded.email.subject=Nightly build succeeded!
]]></source>

        <p><code>monitor.properties</code> should be placed right next
        to your compiled <code>BuildMonitor.class</code>.  To use it,
        invoke Ant like:</p>
        
        <source><![CDATA[
ant -listener BuildMonitor -logfile build.log
]]></source>

        <p>Make sure that <code>mail.jar</code> from JavaMail and
        <code>activation.jar</code> from the 
        <a href="http://java.sun.com/products/javabeans/glasgow/jaf.html">Java
        Beans Activation Framework</a> are in your <code>CLASSPATH</code>.</p>

      </answer>
    </faq>

    <faq id="listener-properties">
      <question>How do I get at the properties that Ant was running
      with from inside BuildListener?</question>

      <answer>
        <p>You can get at a hashtable with all the properties that Ant
        has been using through the BuildEvent parameter. For
        example:</p>

        <source><![CDATA[
public void buildFinished(BuildEvent e) {
    Hashtable table = e.getProject().getProperties();
    String buildpath = (String)table.get("build.path");
    ...
}
]]></source>

        <p>This is more accurate than just reading the same property
        files that your project does, since it will give the correct
        results for properties that were specified on the Ant command line.</p>
      </answer>
    </faq>
    
  </faqsection>

  <faqsection title="Known Problems">
    <faq id="remove-cr">
      <question>&lt;chmod&gt; or &lt;exec&gt; doesn&apos;t work in Ant
        1.3 on Unix</question>
      <answer>

        <p>The <code>antRun</code> script in <code>ANT_HOME/bin</code>
        has DOS instead of Unix line endings; you must remove the
        carriage-return characters from this file.  This can be done by
        using Ant&apos;s <code>&lt;fixcrlf&gt;</code> task
        or something like:</p>

        <source><![CDATA[
tr -d '\r' < $ANT_HOME/bin/antRun > /tmp/foo
mv /tmp/foo $ANT_HOME/bin/antRun
]]></source>
      </answer>
    </faq>

    <faq id="javadoc-cannot-execute">
      <question>JavaDoc failed: java.io.IOException: javadoc: cannot execute</question>
      <answer>
        <p>There is a bug in the Solaris reference implementation of
        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>).
        This also appears to be true under Linux. Moving the JDK to
        the front of the PATH fixes the problem.</p>
      </answer>
    </faq>
  </faqsection>

</document>
