Adding basic build automation for a web application project using ANT

We add the ability to build the projects source and generate an executable artifact that can be deployed to an application server capable of running WAR files. In this example we are using tomcat and thus also add support for managing the application through ANT to aid development.

We also add eclipse launch configurations so the developer can easily execute specific ant targets rather than typing they via the command link or executing them from eclipses ANT view.

Creating ANT build.xml

The build.xml goes at the root of the project and within it we add the following public.

  1. Clean – responsible for cleaning generated files that are not part of the source of the application i.e. .class files. Basically clean should be able to revert the workspace to the same state repeatedly and that should mirror the state of the project when checked out of source control.
  2. Compile – responsible for compiling all source files required for the application. Thus it will require knowledge of the dependencies required for the source to compile.
  3. Test – this target will invoke all tests that are added. The method behind the development of this software is that developers add tests as new functionality is added and all tests should be passing before checking the code back into source control.
  4. Build – this target is responsible for generating the software deliverable we need;  A WAR file. It cleans, compiles, tests and then packages up the compiled code into a WAR file for deployment to a web container.

Adding tomcat support for Development

We can use the catalina-ant.jar file from the tomcat distribution and create macros around them to allow developers to quickly deploy, undeploy applications on a specific tomcat instance.

To do this we create, and tomcat-macros.xml files. Then we adding the following public targets to our build.xml file

  1. deploy
  2. undeploy

Using Eclipse External Tool Configurations

To make things even easier, we can integrate our IDE (Eclipse) and our build tool (ANT) and create configurations that we can maintain in source control. As these are IDE specific, they can be contained within a folder within the project but the build itself knows nothing of this folder.

Choose option from eclipse configuration menu:

The project structure after build automation has been added

Note: the eclipse specific launch configuration files


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: