Professional Documents
Culture Documents
war file
W(eb) AR(chive)
How To
WAR file structure The static HTML files and JSPs are stored in the top level directory.
The Servlet and related Java[tm] technology class files must be stored in
the WEB-INF/classes directory.
Any auxiliary library JAR files must be stored in the WEB-INF/lib directory.
The deployment descriptor is stored as a file named web.xml in the WEBINF directory.
Creating the web.xml deployment descriptor - 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.
Recallabout web.xml
Servlets
The simplest form of deployment descriptor that is needed to deploy a Java[tm]
Servlet is as follows (assumes the header is preceding):
<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>mypackage.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
</web-app>
The <servlet-name> element is how the Servlet is known within the XML file, the
<servlet-class> is the fully qualified Java programming language class name of the
Servlet; this Java programming language class needs to be located in the WEBINF/classes directory. Thus, for the previous example this would be reflected in the
directory structure: WEB-INF/classes/mypackage/HelloServlet.class.
JSPs
JSPs can be deployed in a WAR file in three ways:
Precompiling
By precompiling the JSP, you have a Servlet. You can reference the
JSP's compiled class (Servlet) and also locate the class as in the
example from the "Servlets" section of this article. However, the
<url-pattern> could be something like Foo.jsp, to signify that it
is/was a JSP. For more information, see the JSP Specification note
in the References section of this article.
Referencing
You can reference the JSP file in web.xml; by using the example in
the "Servlets" section and replacing <servlet-class> with <jsp-file>.
In this case the <jsp-file> root is the root of the WAR file, unlike the
Servlet scenario.
To unpack
If you need to unzip the war file:
Unpacking the Application Files
A WAR file is basically a Java JAR file, or ZIP file.
Copy the app.WAR file from the installation media to the
directory you would like to install them to.
Create the sub-directory for the web application.
Change to the sub-directory.
Unzip the files using the command
jar -xf ../app.WAR
In fact
I never got the webapp working via the
.war file
I was not able to unzip using jar xf
either.
These problems may have been due to
the path setting I had when I used jar to
create the war file.
In any case, winzip can unpack a war file
and it is working fine now.