ant build.xml refactor

A couple of improvements for build.xml. Fixes #2340
/cc @cmaglie