|
Home TOC Index |
|
Search
Feedback |
Web Application Archives
Web clients are packaged in Web application archives. In addition to Web components, a Web application archive usually contains other files, including the following:
- Server-side utility classes (database beans, shopping carts, and so on). Often these classes conform to the JavaBeans component architecture.
- Static Web content (HTML, image, and sound files, and so on).
- Client-side classes (applets and utility classes).
Web components and static Web content files are called Web resources.
A WAR has a specific 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: servlets, utility classes, and JavaBeans componentslib: A directory that contains JAR archives of libraries (tag libraries and any utility libraries called by server-side classes).You can also create application-specific subdirectories (that is, package directories) in either the document root or the
WEB-INF/classesdirectory
Note: When you add classes and archives to a WAR,deploytoolautomatically packages them in theWEB-INFsubdirectory. This is correct for Web components and server-side utility classes, but incorrect for client-side classes such as applets and any archives accessed by applets. To put client-side classes and archives in the correct location, you must drag them to the document root after you have added them to the archive.
Creating a WAR File
When you add the first Web component to a J2EE application,
deploytoolautomatically creates a new WAR file to contain the component. A later section describes how to add a Web component.You can also manually create a WAR in three ways:
- With the
packagertool distributed with the J2EE SDK. This tool is described in the section Packager Tool.- With the
wartask of theantportable build tool.Antis used to build the J2EE Tutorial examples. The example application described in the section The Example JSP Pages usesantto create the 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 the following command in the top-level directory of the application:
jar cvfarchiveName.war .Note that to use any of these methods, you must also manually create a deployment descriptor in the correct format.
Adding a WAR File to an EAR File
If you manually create a WAR file or obtain a WAR file from another party, you can add it to an existing EAR file as follows:
- Select a J2EE application.
- Select File
Add
Web WAR.
- Navigate to the directory containing the WAR file, select the WAR file, and click Add Web WAR.
See The Example JSP Pages for an example.
You can also add a WAR file to a J2EE application using the
packagertool. The Duke's Bank application described in Building, Packaging, Deploying, and Running the Application usespackager.Adding a Web Component to a WAR File
The following procedure describes how to create and add the Web component in the
Hello1Appapplication 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
j2eetutorial/examplesand build the example by runningant hello1. For detailed instructions, see About the Examples).- Create a J2EE application called
Hello1App.
- Select File
New
Application.
- Click Browse.
- In the file chooser, navigate to
j2eetutorial/examples/src/web/hello1.- In the File Name field, enter
Hello1App.- Click New Application.
- Click OK.
- Create the WAR file and add the
GreetingServletWeb component and all of theHello1Appapplication content.
- Invoke the Web component wizard by selecting File
New
Web Component.
- In the combo box labelled Create New WAR File in Application select Hello1App. Enter
Hello1WARin the field labeled WAR Display Name.- Click Edit to add the content files.
- In the Edit Contents dialog box, navigate to
j2eetutorial/examples/build/web/hello1. SelectGreetingServlet.class,ResponseServlet.class, andduke.waving.gif, and click Add. Click OK.- Click Next.
- Select the Servlet radio button.
- Click Next.
- Select
GreetingServletfrom the Servlet Class combo box.- Click Finish.
- Add the
ResponseServletWeb component.
Note: You can add JSP pages to a WAR file without creating a new Web component for each page. You simply select the WAR file, click Edit to edit the contents of the WAR, and add the pages. The JSP version of the Hello, World application, described in Updating Web Clients, shows how to do this. If you choose this method, you will not be able to specify alias paths (described in Specifying an Alias Path) for the pages.
|
Home TOC Index |
|
Search
Feedback |