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.
The obvious choice was to use Ant's mail task, which comes predefined with Ant:
<target name="notify" description="notify team">
<mail subject="latest deployment">
<from address="me@gmail.com" />
<to address="jimmy@yahoo.com" />
<message>A new build has been pushed out to prod</message>
</mail>
</target>
However this results in the following runtime exception:
java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage
This is because Ant's mail task depends on JavaMail and JavaBeans Activation Framework, 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.
This issue has already been discussed on this post: ant mail task using mail and activation jar in external location. Based on the answers there seem to be two solutions.
The first is to manually put these library dependencies on the ant classpath. This can be done using the -lib
command line argument, or in eclipse one can use Window > Preferences > Ant > Runtime > Global Entries
, and then add mail.jar
and activation.jar
(I'm pretty sure this amounts to the same thing as -lib
, 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.
The other solution in the linked post mentions a way to do the above programmatically, by calling Ant from itself:
<exec executable="ant">
<arg value="-lib"/>
<arg value="PATH_TO_MY_LIB"/>
<arg value="target"/>
</exec>
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.
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 wasn't predefined by Ant this would be easier. Hopefully I'm missing something.