aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Mail task on Target failure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Mail task on Target failure" Watch "Mail task on Target failure" New topic
Author

Mail task on Target failure

vinodh kumar
Ranch Hand

Joined: Jan 07, 2008
Posts: 41
Hi,

I have an ant project where there is a set of targets. After successful completion of all targets I call mail target at the end to send a mail with attached logs with message build successful.

Now, my challenge is if one of the target fails then build exits so it will not proceed to mail target which is the last one to perform on completion of all. How can I use mail target to send mail on any target failure?

Any hints?

-Vinodh Kumar
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

Based on the command line options (http://ant.apache.org/manual/index.html) your two best bets are:

1) Try the -k option

2) Write a CustomExitCode class and invoke the mail target from within it.

Of course, you could always create a script that does:

ant xxx yyy
ant mail

That way the mail target would always run. You'd probably have to tweak the mail target since it would be mailing the result from the prior ant run.

Another thought: having a "finally" target that runs before exit whether the build passed or failed is a good idea. If you created a patch to do that you could submit it back to the community.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mail task on Target failure
 
Similar Threads
Ant script not running in Eclipse 3.4
Failing to send an email externally
how to get status mail using javamail.
Ant target is not displaying results in eclipse
IntelliJ 4.0, Ant and JUnit