Explain the purpose of a WAR file and describe the contents of a WAR file, how one
may be constructed.
Web applications can be packaged and signed into a Web ARchive format (WAR)
file using the standard Java archive tools. For example, an application for issue
tracking might be distributed in an archive file called issuetrack.war.
When packaged into such a form, a META-INF directory will be present which
contains information useful to Java archive tools. This directory must not be
directly served as content by the container in response to a Web client’s request,
though its contents are visible to servlet code via the getResource
and getResourceAsStream calls on the ServletContext.
Also, any requests to access the resources in META-INF directory must
be returned with a SC_NOT_FOUND(404) response.
A WAR usually contains following resources:
Servlets, JavaServer Pages (JSP), Custom Tag Libraries.
Server-side utility classes (database beans, shopping carts, and so on).
Static web resources (HTML, image, and sound files, and so on).
Client-side classes (applets and utility classes).
The directory structure of a Web application consists of two parts. The first part is the
public directory structure containing HTML/XML documents, JSP pages, images, applets,
and so on. The container appropriately serves the directory's contents against incoming
requests. The second part is a special WEB-INF directory that contains
the following files and directories:
web.xml - the web application deployment descriptor.
Tag Library Descriptor files.
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).
tags/ - a directory that contains Tag files
(made easily accessible to JSPs without the need to explicitly
write a Tag Library Descriptor files).
The structure of the WAR files looks like this:
WEB-INF/
WEB-INF/web.xml
WEB-INF/classes/
WEB-INF/lib/
WEB-INF/tags/
To prepare the web application for deployment, package it in a WAR file
using the following jar utility command from the top-level
directory of the application:
jar cvf web_app.war .
where web_app is the web application name.
Visit
http://java.boot.by
for the updates.