You want to set up your Ant buildfile to use Tomcat's Manager application.
Create an Ant buildfile that invokes Ant targets to start and stop Tomcat, along with targets to install and remove web applications from Tomcat.
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.
The following targets are executed in the following order when a user types ant deploy on the command line:
The prepare target executes first to set up the build environment.
The compile target compiles the out-of-date code.
The war target creates a .war file that is ultimately deployed to Tomcat.
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.
The init target sets two properties: is.tomcat.started and is.webapp.deployed.
If the property is.webapp.deployed is "true", the undeploy target is invoked.
Finally, the deploy target is invoked to deploy the new WAR file.
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.