WAR (file format)

Web ARchive
Filename extension .war
Developed by Sun Microsystems
Container for JSP, Java Servlet
Extended from JAR

In software engineering, a WAR file (or Web application ARchive[1]) is a JAR file used to distribute a collection of JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static web pages (HTML and related files) and other resources that together constitute a web application.

Content and structure

A WAR file may be digitally signed in the same way as a JAR file in order to allow others to determine what source the code came from.

There are special files and directories within a WAR file:

Advantages of WAR files

Disadvantages of WAR files

One disadvantage of web deployment using WAR files (especially in very dynamic environments) stems from the restriction that minor changes cannot be made during runtime. Any change whatsoever requires regenerating and redeploying the entire WAR file.

Example

The following sample web.xml file demonstrates the declaration and association of a servlet:

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE web-app
     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
     "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
 
 <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>
 
     <resource-ref>
         <description>
             Resource reference to a factory for javax.mail.Session
             instances that may be used for sending electronic mail messages,
             preconfigured to connect to the appropriate SMTP server.
         </description>
         <res-ref-name>mail/Session</res-ref-name>
         <res-type>javax.mail.Session</res-type>
         <res-auth>Container</res-auth>
     </resource-ref>
 </web-app>

The /WEB-INF/classes directory is on the ClassLoader's classpath. (The classpath consists of a list of locations from which .class files can be loaded and executed by the JVM.) The /WEB-INF/classes directory contains the classes associated with the web application itself.

Any JAR files placed in the /WEB-INF/lib directory will also be placed on the ClassLoader's classpath.

See also

Related file formats:

References

  1. "What's New in Java Servlet API 2.2?". JavaWorld(Reprinted by Oracle Corporation). October 1999. Retrieved 2014-08-26.

External links

This article is issued from Wikipedia - version of the Friday, April 22, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.