How to Build Java Projects on-the-fly using Apache Ant’s API
I always wanted to post a tutorial on how to build Java projects using Apache Ant’s Java API. I had done a project in my final year which required an on-the-fly building of the portlets. The building included compiling the code, creating necessary folders to put the executables & other files and finally creating a .war file to deploy on the server. I was pretty new to Java development then, so I needed some kind of tutorial on how to use Ant’s Java API, but couldn’t find a good one. So I downloaded Ant’s API manual and started learning on my own and decided that once I become knowledgeable enough, I’d post a tutorial so that it becomes helpful to everyone else.
In this tutorial, we’ll learn how to perform things written in Ant’s build.xml file using Java code.
There are some prerequisites which I want you to have a look at before proceeding. Here are they:
- You must have some basic understanding of how Ant works. For example, knowing what are ‘tasks’, ‘targets’, etc. in Ant. If not, there are various online tutorials available to get you started. Google it.
- You must have Ant’s latest API manual which can be found here.
- You must be familiar with basics of Servlets and JSP, as we’ll use them in this tutorial.
- An IDE, preferably Eclipse, as I used it myself and I’ll use it throughout the tutorial. So people out there with other IDEs, I don’t think you’d find it difficult to manage with your favorite IDE as it can be achieved with any Java IDE on the planet.
- Servlet container. I’ve used Apache Tomcat for this tutorial.