10.8 Setting Up Ant to Use Tomcat's Manager Web Application

10.8.1 Problem

You want to set up your Ant buildfile to use Tomcat's Manager application.

10.8.2 Solution

Create an Ant buildfile that invokes Ant targets to start and stop Tomcat, along with targets to install and remove web applications from Tomcat.

10.8.3 Discussion

Setting up a consistent build process is extremely important, especially if you are dealing with application servers that must be running during portions of the build process. For example, Chapter 7 discusses how to write unit tests that execute in a running server. In order for the tests to execute, a server must be started (in this case, Tomcat). To facilitate this process, a buildfile needs to ensure that the server is started before invoking any tasks that require a running server. Figure 10-1 shows a graphical view of the Ant buildfile. Earlier recipes discuss each target, minus the war target and its dependencies.

Figure 10-1. Graphical view of an Ant buildfile

The following targets are executed in the following order when a user types ant deploy on the command line:

  1. The prepare target executes first to set up the build environment.

  2. The compile target compiles the out-of-date code.

  3. The war target creates a .war file that is ultimately deployed to Tomcat.

  4. The start.tomcat uses a custom Ant task to start the server. The build process patiently waits until Tomcat successfully starts or the task times out.

  5. The init target sets two properties: is.tomcat.started and is.webapp.deployed.

  6. If the property is.webapp.deployed is "true", the undeploy target is invoked.

  7. Finally, the deploy target is invoked to deploy the new WAR file.

10.8.4 See Also

The next recipe shows how to set up your Ant buildfile to hot deploy applications to JBoss. Recipe 10.10 discusses how to hot-deploy web applications to JBoss.