WAR File Format (Sun)
   HOME

TheInfoList



OR:

In
software engineering Software engineering is a systematic engineering approach to software development. A software engineer is a person who applies the principles of software engineering to design, develop, maintain, test, and evaluate computer software. The term '' ...
, a WAR file (Web Application Resource or Web application ARchive) is a file used to distribute a collection of
JAR A jar is a rigid, cylindrical or slightly conical container, typically made of glass, ceramic, or plastic, with a wide mouth or opening that can be closed with a lid, screw cap, lug cap, cork stopper, roll-on cap, crimp-on cap, press-on cap, ...
-files,
JavaServer Pages Jakarta Server Pages (JSP; formerly JavaServer Pages) is a collection of technologies that helps software developers create dynamically generated web pages based on HTML, XML, SOAP, or other document types. Released in 1999 by Sun Microsystems, J ...
,
Java Servlet A Jakarta Servlet (formerly Java Servlet) is a Java software component that extends the capabilities of a server. Although servlets can respond to many types of requests, they most commonly implement web containers for hosting web application ...
s,
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
class Class or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used differentl ...
es,
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. T ...
files, tag libraries, static web pages (
HTML The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScri ...
and related files) and other resources that together constitute a
web application A web application (or web app) is application software that is accessed using a web browser. Web applications are delivered on the World Wide Web to users with an active network connection. History In earlier computing models like client-serve ...
.


Content and structure

A WAR file may be digitally signed in the same way as a
JAR A jar is a rigid, cylindrical or slightly conical container, typically made of glass, ceramic, or plastic, with a wide mouth or opening that can be closed with a lid, screw cap, lug cap, cork stopper, roll-on cap, crimp-on cap, press-on cap, ...
file in order to allow others to determine where the source code came from. 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 to which
servlet A Jakarta Servlet (formerly Java Servlet) is a Java software component that extends the capabilities of a server. Although servlets can respond to many types of requests, they most commonly implement web containers for hosting web application ...
a
URL A Uniform Resource Locator (URL), colloquially termed as a web address, is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifie ...
request will be routed. The web.xml file 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.


Advantages of WAR files

* Easy testing and deployment of web applications * Easy identification of the version of the deployed application * All Java EE containers support WAR files *
MVC MVC may refer to: Science and technology * Maximum-value composite procedure, an imaging procedure * Multivariable calculus, a concept in mathematics * Multivariable control, a concept in process engineering * Mechanical vapor compression, a desal ...
structure supports WAR files. Assuming production environments do not promote a fix without sufficient testing prior to deployment, a WAR file has a distinct advantage when properties files are used to identify environment specific variables. For example, an LDAP server in a testing environment may be something like ldaps://testauth.example.com:636. The LDAP server in a production environment is ldaps://auth.example.com:636. An external properties file would define the link with some thing like: LINKED_PAGE=ldaps://testauth.example.com:636 The source code reads the property file to determine the target LDAP server. In this way, developers can be certain that the WAR file tested and verified is exactly the same as that which is being promoted to production.


Disadvantages of WAR files

Some consider web deployment using WAR files to be disadvantageous when minor changes to source code are required for dynamic environments. Each change to source code must be repackaged and deployed in development. This does not require stopping the web server if configured for runtime deployment.


Example

The following sample ''web.xml'' file demonstrates the declaration and association of a
servlet A Jakarta Servlet (formerly Java Servlet) is a Java software component that extends the capabilities of a server. Although servlets can respond to many types of requests, they most commonly implement web containers for hosting web application ...
: HelloServlet mypackage.HelloServlet HelloServlet /HelloServlet 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. mail/Session javax.mail.Session Container The /WEB-INF/classes directory is on the
ClassLoader The Java Class Loader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. Usually classes are only loaded on demand. The Java run time system does not need to know about files and file syste ...
'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

*
EAR (file format) EAR (''E''nterprise ''A''pplication a''R''chive) is a file format used by Jakarta EE for packaging one or more modules into a single archive so that the deployment of the various modules onto an application server happens simultaneously and cohere ...
* JAR (file format)


References


External links


Packaging Web Archives
(The Jakarta EE 8 Tutorial)
JSR 154: JavaTM Servlet 2.4 Specification
{{DEFAULTSORT:War File Format (Sun) Archive formats Java enterprise platform