Before describing how to organize your source code directories,
it is useful to examine the runtime organization of a web application.
Prior to the Servlet API Specification, version 2.2, there was little
consistency between server platforms. However, servers that conform to
the 2.2 specification are required to accept a Web Application Archive
in a standard format, which is discussed further below.
A web application is defined as a hierarchy of directories and files in a
standard layout. Such a hierarchy can be accessed in its "unpacked" form,
where each directory and file exists in the filesystem separately,
or in a "packed" form known as a Web ARchive, or WAR file.
The former format is more useful during development, while the latter
is used when you distribute your application to be installed.
The top-level directory of your web application hierarchy is also the
document root of your application. Here, you will place the HTML files
and JSP pages that comprise your application's user interface.
When the system administrator deploys your application into a particular server,
he or she assigns a context path to your application. Thus, if
the system administrator assigns your application to the context path /catalog,
then a request URI referring to /catalog/index.html will retrieve the index.html
file from your document root.
To facilitate creation of a Web Application Archive file in the required format, it is convenient to arrange the files that Tomcat actually uses when executing your application in the same organization as required by the WAR format itself. To do this, you will have the following contents in your application's "document root" directory:
When you install an application into Tomcat (or any other 2.2-compatible server),
the classes in the WEB-INF/classes/ directory, as well as all classes in JAR
files found in the WEB-INF/lib/ directory, are added to the class path for
your particular web application. Thus, if you include all of the required
library classes in one of these places (be sure to check licenses for
redistribution rights for any third party libraries you utilize),
you will simplify the installation of your web application -- no adjustment to
the system class path will be necessary.
As mentioned above, the WEB-INF/web.xml file contains the Web Application
Deployment Descriptor for your application. As the filename extension implies,
this file is an XML document, and defines everything about your application
that a server needs to know (except the context path, which is assigned by t
he system administrator when the application is deployed).
The complete syntax and semantics for the deployment descriptor is defined
in Chapter 13 of the Servlet API Specification, version 2.2. Over time,
it is expected that development tools will be provided that create and edit
the deployment descriptor for you. In the meantime, to provide a starting point,
a basic web.xml (text file) is provided in the doc/appdev. This file includes
comments that describe the purpose of each included element.
In order to be executed, a web application must be integrated with, or installed in, a servlet container. This is true even during development. We will describe using Tomcat to provide the execution environment. A web application can be deployed in Tomcat by one of three different approaches:
Integrating your app with other servlet containers will be specific to each
container, but all containers compatible with the Servlet API Specification
(version 2.2) are required to accept a web application archive file.