Before discussing the organization of source code directories in Tomcat, it is useful to examine the runtime organization of a web application. 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 file system 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 the context root of your application. Here, you will place the HTML files and JSP pages that comprise your application's user interface. Thus, if the context path is /catalog, then a request URL referring to /catalog/index.html will retrieve the index.html file.
Standard Directory Layout
To facilitate creation of a Web Application Archive file in the required format, it is convenient to arrange the "executable" files of your web application (that is, the files that Tomcat actually uses when executing your app) in the same organization as required by the WAR format itself. To do this, you will end up with the following contents in your application's "context root" directory:
•*.html, *.jsp, etc. - The HTML and JSP pages, along with other files that must be visible to the client browser (such as JavaScript, style sheet files, and images). In larger applications one may choose to divide these files into a subdirectory hierarchy, but for smaller apps, it is generally much simpler to maintain only a single directory for these files.
•/WEB-INF/web.xml - The Web Application Deployment Descriptor for the application. This is an XML file describing the servlets and other components that make up the application, along with any initialization parameters and container-managed security constraints that one wants the server to enforce
•/WEB-INF/classes/ - This directory contains any Java class files (and associated resources) required for the application, including both servlet and non-servlet classes, that are not combined into JAR files. If the classes are organized into Java packages, they must be reflected in this directory hierarchy under /WEB-INF/classes/. For example, a Java class named com.mycompany.mypackage.MyServlet would need to be stored in a file named /WEB-INF/classes/com/mycompany/mypackage/MyServlet.class.
•/WEB-INF/lib/ - This directory contains JAR files that contain Java class files (and associated resources) required for the application, such as third party class libraries or JDBC drivers.
When an application is installed into Tomcat, the classes in the WEB-INF/classes/ directory, as well as all classes in JAR files found in the WEB-INF/lib/ directory, are made visible to other classes within that particular web application. Thus, including all of the required library classes in one of these places will simplify the installation of the web application -- no adjustment to the system class path (or installation of global library files in your server) will be necessary.
Shared Library Files
Like most servlet containers, Tomcat also supports mechanisms to install library JAR files (or unpacked classes) once, and make them visible to all installed web applications (without having to be included inside the web application itself. There are two locations that are commonly used within a Tomcat installation for shared code:
•$CATALINA_HOME/common/lib - JAR files placed here are visible both to web applications and internal Tomcat code. This is a good place to put JDBC drivers that are required for both your application and internal Tomcat use (such as for a JDBCRealm).
•$CATALINA_HOME/shared/lib - JAR files placed here are visible to all web applications, but not to internal Tomcat code. This is the right place for shared libraries that are specific to the application.
A standard Tomcat 4 installation includes a variety of pre-installed shared library files, including:
•The JavaMail 1.2 (and associated JavaBeans Activation Framework) APIs, so you can write mail-enabled web applications.
•The JDBC 2.0 Optional Package APIs, which define things like javax.sql.DataSource.
•The Servlet 2.3 and JSP 1.2 APIs that are fundamental to writing servlets and JavaServer Pages.
An XML Parser compliant with the JAXP (version 1.1) APIs, so that the application can perform DOM-based or SAX-based processing of XML documents.
Web Application Deployment Descriptor
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.
Deployment
In order to be executed, a web application must be deployed on a servlet container. This is true even during development. A web application can be deployed in Tomcat by one of the following approaches:
•Copy unpacked directory hierarchy into a subdirectory in directory $CATALINA_HOME/webapps/. Tomcat will assign a context path to the application based on the subdirectory name chosen. Be sure to restart Tomcat after installing or updating the application.
•Copy the web application archive file into directory $CATALINA_HOME/webapps/. When Tomcat is started, it will automatically expand the web application archive file into its unpacked form, and execute the application that way.
•Use the Tomcat 4 "Manager" web application to deploy and undeploy web applications. Tomcat includes a web application, deployed by default on context path /manager that allows you to deploy and undeploy applications on a running Tomcat server without restarting it.: hyperlink) for more information on using the Manager web application.
Courtsey: Tomcat Docs
Showing posts with label deployment. Show all posts
Showing posts with label deployment. Show all posts
Tuesday, August 14, 2007
Subscribe to:
Posts (Atom)