I had to write a simple Java class to suck information out of a local database and publish it to a remote database using HTTP POST. I vacillated for awhile between using Perl and Java, but ultimately decided on Java because the Oracle JDBC stuff is more portable than DBI for Perl. (I didn’t want to have to figure out how to put DBD::Oracle on every machine where I might want to run this application.) So, I wrote the Java class, and wrote a build script to compile it and run it. I was then going to write a wrapper (in either Perl or the Bourne shell) that I could call using cron, but my coworker kept needling me to do the whole thing in my Ant build file rather than writing the wrapper.

After waffling, I finally looked at the list of basic Ant tasks and figured out that I could, in fact, put the whole thing in a build script and be done with it. So now I have a build script that compiles my code, makes the JAR file, and then runs it. It also has a “runservice” task that checks for a lock file, and if it’s not there, creates a lock file, posts all the records, sends its output to me via email, and then deletes the lock file. If the lock file is present when it runs, it sends me an email letting me know and then it stops. Given that the developers of Ant are dead set on not turning it into another scripting language, it’s amazing how much you actually can do with it.

Update: the emails that my script sends attach a text file with Unix line feeds, which is useless when opened them Notepad, so I whipped out the fixcrlf task and handled that problem as well. Ant is unstoppable.