Setting Up Ant to Use Tomcat’s Manager Web Application
Problem
You want to set up your Ant buildfile to use Tomcat’s Manager application.
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.
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:
The
preparetarget executes first to set up the build environment.The
compiletarget compiles the out-of-date code.The
wartarget creates a.warfile that is ultimately deployed to Tomcat.The
start.tomcatuses a custom Ant task to start the server. The build process patiently waits until Tomcat successfully starts or the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access