|
Manually Creating a Simple Web ARchive (WAR) FileBy Matthew Hosanee(June, 2002) We want to hear from you! Please send us your FEEDBACK. The following article may contain actual software programs in source code form. This source code is made available for developers to use as needed, pursuant to the terms and conditions of this license.
The ReasonThe new way of deploying Java[tm] 2 Platform, Enterprise Edition (J2EE[tm]) Web modules that include Java[tm] Servlets and JavaServer Pages[tm] (JSP[tm]) relies on packaging the application and associated files into a WebARchive (WAR) file. This seems simple, as the WAR file is the same format as a JavaARchive (JAR) file. However, you also need to create an eXtensisible Markup Language (XML) deployment descriptor (WEB-INF/web.xml) file.
There are tools that can do this for you, such as those in the
Java[tm] Web Services Developer Pack (free download
here), or tools that come with iPlanet[tm] Application Server. However, you may not
want to download or buy these products.
How To
The following is the mandatory header of the web.xml document.
This defines the document as an XML file and relates the syntax of the
file to the DOCTYPE resource specified. Servlets
The simplest form of deployment descriptor that is needed to deploy
a Java[tm] Servlet is as follows (assumes the header is preceding): The <url-pattern> is how the Servlet is referenced from
a Universal Resource Indicator(URI) - see the "Accessing the Content" section of this article.
According to the Servlet specification it is recommended that you include
a mapping to avoid any potential issues.
All of these elements are documented in the Servlet specifications.
JSPs can be deployed in a WAR file in three ways:
After you have created your WEB-INF directory, the deployment descriptor, and have put the relevant files in the correct directories, you can use the "jar" utility from the Java[tm] Development Kit distribution to create the WAR file. Check the tools documentation for the full syntax. The command you could use is (assumes you are at the top level of the directory structure in which you assembled the WAR contents): jar cvf mywar.war WEB-INF {related top-level files or directories} You can then deploy mywar.war using, for example, iPlanet[tm] Application Server, iPlanet[tm] Web Server or any J2EE compliant application server or Web container. The content is generally accessed as follows: http://host:port/context/{maping or file} The context could be set in the deployment phase or set automatically by the application. For example, deploying to iPlanet WebServer 6.x using wdeploy allows you to specify the context name; but iPlanet Application Server 6.x generally uses the WAR file name as the context. References The Java Web Services Tutorial The Servlet/JSP Specification The iPlanet Application Server Developer's Guide The iPlanet Web Server, Enterprise Edition Programmer's Guide to Servlets | |||||||||||||||||||||||||||||||||||||||