WAR (Sun file format)
3294583
206798877
2008-04-20T01:04:57Z
Tokek
185509
links: +link to web application, KDE WAR already linked once
{{dablink|This article is about the WAR file format of Sun Microsystem. For the KDE WAR file format, please see [[KDE WAR (file format)]].}}
{{Infobox file format
| name = Web ARchive
| extension = <tt>.war</tt>
| mime =
| owner = [[Sun Microsystems]]
| creatorcode =
| genre =
| containerfor = [[JavaServer Pages|JSP]], [[Java Servlet]]
| containedby =
| extendedfrom =
| extendedto =
}}
In [[computing]], a '''WAR''' file (which stands for "[[web application]] archive" [http://java.sun.com/developer/technicalArticles/Servlets/servletapi/]) is a [[JAR (file format)|JAR]] file used to distribute a collection of [[JavaServer Pages]], [[Java Servlet|servlets]], [[Java (programming language)|Java]] [[class (file format)|class]]es, [[XML]] files, tag libraries and static Web pages ([[HTML]] and related files) 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 assert that the code is trusted.
There are special files and directories within a WAR file.
The /WEB-INF directory in the WAR file contains a file named web.xml which defines the structure of the web application. If the web application is only serving JSP files, the web.xml file is not strictly necessary. If the web application uses servlets, then the servlet container uses web.xml to ascertain which servlet a URL request should be routed to. web.xml is also used to define context variables which can be referenced within the servlets and it is used to define environmental dependencies which the deployer is expected to set up. An example of this is a dependency on a mail session used to send email. The servlet container is responsible for providing this service.
Unfortunately, one disadvantage of web deployment using WAR files in very dynamic environments is that minor changes cannot be made during runtime. Any change whatsoever requires regenerating and redeploying the entire WAR file.
<source lang="xml">
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>
</source>
The /WEB-INF/classes directory is on the [[Classloader|ClassLoader]]'s [[Classpath (Java)|classpath]]. This is where .class files are loaded from when the web application is executing.
Any JAR files placed in the /WEB-INF/lib directory will also be placed on the ClassLoader's classpath.
== See also ==
Related file formats:
* [[EAR (file format)]]
* [[JAR (file format)]]
== External links ==
*[http://access1.sun.com/techarticles/simple.WAR.html Sun Microsystems: Manually Creating a Simple Web ARchive (WAR) File]
[[Category:Archive formats]]
[[Category:Java enterprise platform]]
[[de:Web Archive]]
[[fr:WAR (format de fichier)]]
[[ja:WAR (アーカイバ)]]
{{Compu-lang-stub}}