Home TOC |
Search
Feedback |
Packaging Web Components
You add web components to a J2EE application in a package called a web application archive (WAR), which is a JAR similar to the package used for Java class libraries. A WAR usually contains other resources besides web components, including:
- Server-side utility classes
- Static web resources (HTML, image, and sound files, and so on)
- Client-side classes (applets and utility classes)
A WAR has a specific hierarchical directory structure. The top-level directory of a WAR is the document root of the application. The document root is where JSP pages, client-side classes and archives, and static web resources are stored. The document root contains a subdirectory called WEB-INF, which contains the following files and directories:
- web.xml - the web application deployment descriptor
- Tag library descriptor files (see Tag Library Descriptors).
- classes - a directory that contains server-side classes: servlet, utility classes, and JavaBeans components.
- lib - a directory that contains JAR archives of libraries (tag libraries and any utility libraries called by server-side classes).
When you add files to a WAR, deploytool automatically packages them in the correct directory.
Note: The J2EE SDK version 1.3 beta deploytool packages client-side classes and archives in the WEB-INF subdirectory instead of the document root. As a consequence, the tutorial example that includes an applet (discussed in The Example JSP Pages) uses a WAR created by the ant make tool.
Creating a WAR
When you add the first web component to a J2EE application, deploytool automatically creates a new WAR to contain the component. A later section describes how to add a web component.
You can also manually create a WAR with the JAR tool distributed with the J2SE. If you arrange your application development directory in the structure required by the WAR format, it is straightforward to create a web application archive file in the required format. You simply execute
jar cvf archiveName.war .in the top-level directory of the application. Note that in order to use this method, you must also manually create a deployment descriptor in the correct format.
Adding a WAR to a J2EE Application
If you manually create a WAR or you obtain a WAR from another party, you can easily add it to an existing J2EE application as follows:
- Select a J2EE application.
- Select File->Add Web WAR to Application or click the Add Web WAR to Application button.
- Navigate to the directory containing the WAR, select the WAR, and click Add Web WAR.
See The Example JSP Pages for an example.
Adding a Web Component to a WAR
The following procedure describes how to add the web components in the hello1 application to a WAR. Although the web component wizard solicits WAR and component-level configuration information when you add the component, this chapter describes how to add the component and provide configuration information at a later time using application, WAR, and web component inspectors:
- Go to examples/src and build the example by running ant hello1 (see How to Build and Run the Examples).
- Create a J2EE application called hello1.
- Select File->New Application or the New Application button.
- Enter hello1.ear in the Application File Name field.
- Click OK.
- Add the greeting web component and all the of the hello2 application content.
- Invoke the web component wizard by selecting File->New Web Component or clicking the New Web Component button.
- In the combo box labelled Create New WAR File in Application select the hello1 application. Enter hello1 in the field labeled WAR Display Name.
- Click Add to add the content files.
- In the Edit Contents dialog, navigate to examples/build/web/hello1. Select GreetingServlet.class, ResponseServlet.class, and duke.waving.gif, and click Add. Click OK.
- Click Next.
- Select the servlet radio button.
- Click Next.
- Select GreetingServlet from the Servlet Class combo box.
- Type greeting in the Web Component Name field.
- Click Next and then click Finish.
- Add the response web component.
- Invoke the web component wizard by selecting File->New Web Component or clicking the New Web Component button.
- In the combo box labelled Add to Existing WAR File select the hello1 WAR.
- Click Next.
- Select the servlet radio button.
- Click Next.
- Select ResponseServlet from the Servlet Class combo box.
- Type response in the Web Component Name field.
- Click Next and then click Finish.
Home TOC |
Search
Feedback |