Sunday, 22 March 2009

Issue with Ant Copy task

This is something that I faced a few months ago. We had spent a few weeks developing build scripts for our deployment. We were entering the period where we prepared things for our final go live, and one of the suggestions was that we build a deployment script that could replace the current one. The existing one did not create a single tar file that could be extracted, it created two files - one with all the property files for all the services to be deployed and one with the jar files. Extracting these two one after the other was all that was needed, but it was not elegant.

So we asked a developer to merge these two scripts and thought that would be it. On the day we did the deployment to DEV, the services refused to start. Reason - corrupted files. We switched to plan B - used the old scripts and viola! the services start!

We duly fired a failure mail and decided to dissect things the next day. And after half a day when I figured it, I kicked myself.

Ant has a copy task that lets you perform token replacement. This basically lets you prepare files that can vary depending on environment etc and set the values when building the script. This is how it is used


< copy todir='../backup/dir'>
< fileset dir='src_dir'/>
< filterset>
< filter token='TITLE' value='Foo Bar'/>
< /filterset>
< /copy>


Apparently, this task does not differentiate between ASCII and binary files. It does the replacement on ANY file. Our original scripts were separate. So the jar files were copied in a copy task that did not do filtering. When we merged the scripts, we put all the files into a single task.

Once I moved the jar files and the property files into separate tasks, the scripts worked fine.


So it was a simple Ant task that was the issue!!

0 comments: