title: How to programmatically add Ant library dependencies for mail task
body: <p>I've been tasked with creating automated notifications for our Ant build scripts. This is so that when someone pushes out a deployment, our team can automatically receive an email about it.</p>
  
  <p>The obvious choice was to use <a href="http://ant.apache.org/manual/Tasks/mail.html" rel="nofollow noreferrer">Ant's mail task</a>, which comes predefined with Ant:</p>
  
  <pre><code>&lt;target name="notify" description="notify team"&gt;
      &lt;mail subject="latest deployment"&gt;
          &lt;from address="me@gmail.com" /&gt;
          &lt;to address="jimmy@yahoo.com" /&gt;
          &lt;message&gt;A new build has been pushed out to prod&lt;/message&gt;
      &lt;/mail&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>However this results in the following runtime exception:</p>
  
  <pre><code>java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage
  </code></pre>
  
  <p>This is because Ant's mail task depends on <a href="http://en.wikipedia.org/wiki/Javamail" rel="nofollow noreferrer">JavaMail</a> and <a href="http://en.wikipedia.org/wiki/JavaBeans_Activation_Framework" rel="nofollow noreferrer">JavaBeans Activation Framework</a>, libraries which are apparently not included with its distribution. Why Ant would define a task that depended on a library but not include that library is unclear to me.</p>
  
  <p>This issue has already been discussed on this post: <a href="https://stackoverflow.com/q/8313100/697449">ant mail task using mail and activation jar in external location</a>. Based on the answers there seem to be two solutions.</p>
  
  <p>The first is to manually put these library dependencies on the ant classpath. This can be done using the <code>-lib</code> command line argument, or in eclipse one can use <code>Window &gt; Preferences &gt; Ant &gt; Runtime &gt; Global Entries</code>, and then add <code>mail.jar</code> and <code>activation.jar</code> (I'm pretty sure this amounts to the same thing as <code>-lib</code>, correct me if I'm wrong). But this solution is undesirable for our team because it would mean every one of us would have to manually carry out these steps. I'm looking for a way to simply commit my notification code, and it should work on another eclipse install after svn update.</p>
  
  <p>The other solution in the linked post mentions a way to do the above programmatically, by calling Ant from itself:</p>
  
  <pre><code>&lt;exec executable="ant"&gt;
      &lt;arg value="-lib"/&gt;
      &lt;arg value="PATH_TO_MY_LIB"/&gt;
      &lt;arg value="target"/&gt;
  &lt;/exec&gt;
  </code></pre>
  
  <p>The problem with this is that the Ant command line tool is apparently only included with the full install, not the eclipse distribution. So again there's no way to make it work without some manual action by anyone wanting to use the mail task.</p>
  
  <p>Is there any way I can automate this without adding another annoying step to project setup? I really don't understand why this is so hard to achieve - it seems like if the mail task <em>wasn't</em> predefined by Ant this would be easier. Hopefully I'm missing something.</p>