Sunday, November 4, 2007

Eclipse - running ant which has got mail task

Have you ever written mail ant task and try to run in Eclipse?


<target name="mail" if="report.dir">
<mail mailhost="${mail.host}" mailport="25"
subject="${mail.subject}" messagefile="${log.file}"
tolist="${to.address}">
<from address="${from.address}"/>
<replyto address="${reply.to}"/>
<attachments>
<fileset dir="${report.dir}/html">
<include name="**/*.html"/>
</fileset>
</attachments>
</mail>
</target>


Failed to initialise MIME mail: javax/mail/MessagingException
This task fails with this error. This is because mail task need mail.jar and activation.jar and this does not come with ant installation. There are two steps need to be added here,

1. Download mail.jar and activation.jar and place under ANT_HOME/lib folder
2. Eclipse cannot automatically detect this, so it needs to be manually configured
a. Select windows > preferences
b. Select Ant > Runtime
c. Select Global entries
d. Click on "Add External jars" and add mail.jar and activation.jar

Now execute ant, it should work.

No comments: