Let’s say I have several web applications that I need to deploy on the same web server. If I use a regular Ant task, I would have to replicate these lines of code for every application:
I know it does not look that bad, but this is just a short sample. In a real world case, I also need to compile the application, generate a WAR file, deploy it, generate a client stub, etc. So, the Ant build.xml tends to grow very fast. In one of my previous project with about #5,000 the build.xml was over 700 lines of code.
Here is a solution that I like. I define a macro that deploys my application:
<attribute name="name" />
targets=" myWebSiteDomain " />
Once it is defined, I can deploy a set of applications simply by calling:
<myApp.deploy name="myApp1" />
<myApp.deploy name="myApp2" />
<myApp.deploy name="myAppN" />
The macro above can be enhanced to do other tasks. I find it very convenient. I think it is a good practice to replace lots of repetitive tasks in Ant build file with a macro.