Building, Installing, Deploying, and Running AddressBook
To install the address book, change to the AddressBook directory, and issue the
install command to Ant:
$ cd AddressBook $ ant install
If the install failed, check that the
tomcat-users.xml file in
conf directory is set up correctly, and that
catalina-ant.jar in Tomcat's
server/lib directory has
been copied into Ant's
ant install automatically triggers a number of other
Ant targets, in this sequence:
ant build, and
package, as follows:
ant initinitializes the time stamp.
ant preparecreates a
wardirectory structure in the AddressBook directory, as follows: a
war/WEB-INF/classesdirectory, and a
ant buildbuilds the Web Application by copying the
jspfiles into the
wardirectory, copying the
context.xmlfiles into the
war/META-INFdirectory, copying the
web.xmlfile into the
war/WEB-INFdirectory, and compiling any Java files into the
ant packagecreates the Web archive file from the
wardirectory. The Web archive file is a .jar file and is created using the
ant installinstalls the Web archive file into Tomcat using the
war/META-INF/context.xmlconfiguration file. Note that there is no need to log in as root or Tomcat to install AddressBook in Tomcat; your normal user account will do fine.
AddressBook/build.propertiesto access Tomcat in a secure manner.
This is controlled by the depends option; see
AddressBook/build.xml for details.
Figure 4 shows the
war directory structure populated with the
various files that compose the AddressBook Web application.
Point your browser at
to test the AddressBook Web application. You can see AddressBook's Home Page in
Figure 5. If it failed to execute correctly, check that you have put your
database's JDBC driver file in Tomcat's
Finally, check in Tomcat's
logs directory -- it contains various
text files that will help you investigate the problem.
Try to add a new address, then modify it, then delete it, then add another
new address. You will see that the
id keeps incrementing
The Development Cycle
AddressBook was installed, Tomcat called
AddressBook.ContextListener.contextInitialized, which created an
AddressBook.AddressesDB constructor established a connection using
AddressBook.ContextListener.contextInitialized then saved the
AddressBook.AddressesDB as a servlet attribute called
Home.jsp was first called up, Tomcat
compiled and executed it.
Home.jsp retrieved the servlet attribute
addressesDB and acquired the instance of
Home.jsp then read the
addresses from the database and displayed them. As you proceeded through the
other JSPs for the first time, they were also compiled and executed. The other
JSPs access the database in the same way as
ant stop to stop the AddressBook Web application. Tomcat
will automatically call
AddressBook.ContextListener.contextDestroyed and retrieve the same
addressesDB servlet attribute and acquire the same instance of
AddressBook.ContextListener.contextDestroyed will then close the
database connection and remove the
ant start to start the the AddressBook Web application. Tomcat will automatically call
AddressBook.ContextListener.contextInitialized and the entire process will repeat.
When developing a Web application, the cycle goes as follows: make changes
to your software; issue
ant install to build and install the Web
application; point your browser at
http://localhost:8080/applicationName (or simply hit the browser's refresh button) to test the Web application; issue
ant remove to remove the Web application's
context; repeat. When you are happy with the application, issue
deploy to permanently deploy the Web application. Now your Web
application will be available after you restart Tomcat, or even after you
reboot your server and start Tomcat. Issue
ant undeploy to
permanently undo deployment of the Web application.
Instead of Ant, you can use the Tomcat manager Web page. Point your browser
http://localhost:8080/manager/html/list. You can see Tomcat's Manager Web page in Figure 6.
Alternatively, you can issue these URLs directly: