WAR (file format)

Last updated
Web ARchive
Filename extension
.war
Internet media type application/java-archive
Magic number PK\x03\x04 (standard ZIP file)
Developed by Sun Microsystems
Container for JSP, Java Servlet
Extended from JAR

In software engineering, a WAR file (Web Application Resource [1] or Web application ARchive [2] ) is a file used to distribute a collection of JAR-files, 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.

Contents

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 where the source code came from.

There are special files and directories within a WAR file:

Advantages of 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. [3] This does not require stopping the web server if configured for runtime deployment. [4]

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>Resourcereferencetoafactoryforjavax.mail.Session instancesthatmaybeusedforsendingelectronicmailmessages, preconfiguredtoconnecttotheappropriateSMTPserver. </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 Research Articles

Jakarta Enterprise Beans is one of several Java APIs for modular construction of enterprise software. EJB is a server-side software component that encapsulates business logic of an application. An EJB web container provides a runtime environment for web related software components, including computer security, Java servlet lifecycle management, transaction processing, and other web services. The EJB specification is a subset of the Java EE specification.

The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and resources via a name. Like all Java APIs that interface with host systems, JNDI is independent of the underlying implementation. Additionally, it specifies a service provider interface (SPI) that allows directory service implementations to be plugged into the framework. The information looked up via JNDI may be supplied by a server, a flat file, or a database; the choice is up to the implementation used.

Jakarta Server 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, JSP is similar to PHP and ASP, but uses the Java programming language.

<span class="mw-page-title-main">Jakarta Servlet</span> Jakarta EE programming language class

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 applications on web servers and thus qualify as a server-side servlet web API. Such web servlets are the Java counterpart to other dynamic web content technologies such as PHP and ASP.NET.

A web container is the component of a web server that interacts with Jakarta Servlets. A web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet and ensuring that the URL requester has the correct access-rights. A web container handles requests to servlets, Jakarta Server Pages (JSP) files, and other types of files that include server-side code. The Web container creates servlet instances, loads and unloads servlets, creates and manages request and response objects, and performs other servlet-management tasks. A web container implements the web component contract of the Jakarta EE architecture. This architecture specifies a runtime environment for additional web components, including security, concurrency, lifecycle management, transaction, deployment, and other services.

<span class="mw-page-title-main">JAR (file format)</span> Java archive file format

A JAR file is a package file format typically used to aggregate many Java class files and associated metadata and resources into one file for distribution.

<span class="mw-page-title-main">Apache Ant</span> Java software tool

Apache Ant is a software tool for automating software build processes which originated from the Apache Tomcat project in early 2000 as a replacement for the Make build tool of Unix. It is similar to Make, but is implemented using the Java language and requires the Java platform. Unlike Make, which uses the Makefile format, Ant uses XML to describe the code build process and its dependencies.

Java Management Extensions (JMX) is a Java technology that supplies tools for managing and monitoring applications, system objects, devices and service-oriented networks. Those resources are represented by objects called MBeans. In the API, classes can be dynamically loaded and instantiated. Managing and monitoring applications can be designed and developed using the Java Dynamic Management Kit.

<span class="mw-page-title-main">Apache Axis</span> Web service framework

Apache Axis is an open-source, XML based Web service framework. It consists of a Java and a C++ implementation of the SOAP server, and various utilities and APIs for generating and deploying Web service applications. Using Apache Axis, developers can create interoperable, distributed computing applications. Axis development takes place under the auspices of the Apache Software Foundation.

Apache Wicket, commonly referred to as Wicket, is a component-based web application framework for the Java programming language conceptually similar to JavaServer Faces and Tapestry. It was originally written by Jonathan Locke in April 2004. Version 1.0 was released in June 2005. It graduated into an Apache top-level project in June 2007.

<span class="mw-page-title-main">Apache Tapestry</span> Open-source web application framework

Apache Tapestry is an open-source component-oriented Java web application framework conceptually similar to JavaServer Faces and Apache Wicket. Tapestry was created by Howard Lewis Ship, and was adopted by the Apache Software Foundation as a top-level project in 2006.

A deployment descriptor (DD) refers to a configuration file for an artifact that is deployed to some container/engine.

WebSphere Application Server Community Edition (WASCE) was a free-of-charge, certified Java EE 6 application server for building and managing Java applications. Until September 30, 2016, it was IBM's supported distribution of Apache Geronimo that usee Tomcat for servlet container and Axis 2 for web services. Another difference from Apache Geronimo is that WASCE came with Db2 and Informix database drivers, better XML parser libraries and contained the latest patches from unreleased upstream versions. Over 30 WASCE developers were committers in the Apache Geronimo project.

EAR 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 coherently. It also contains XML files called deployment descriptors which describe how to deploy the modules.

The Java API for XML Messaging (JAXM) enables distributed software applications to communicate using XML (and SOAP). JAXM supports both asynchronous and synchronous messaging.

Classpath is a parameter in the Java Virtual Machine or the Java compiler that specifies the location of user-defined classes and packages. The parameter may be set either on the command-line, or through an environment variable.

Apache Click is a page and component oriented web application framework for the Java language and is built on top of the Java Servlet API.

Virgo is an open source, OSGi-based, Java application server. Virgo supports the deployment of OSGi bundles and unmodified Java web applications as well as OSGi-influenced Shared Libraries WARs and Shared Services WARs.

<span class="mw-page-title-main">Json2Ldap</span>

Json2Ldap is a JSON-to-LDAP gateway software, written in Java and developed by Nimbus Directory Services. It provides a JSON-RPC 2.0 interface for web clients to access one or more LDAP v3 - compatible directories. The Json2Ldap web API supports the standard LDAP directory requests as well as several extended operations and controls.

<span class="mw-page-title-main">Spring Boot</span> Application framework for Java platform

Spring Boot is a convention-over-configuration extension for the Spring Java platform intended to help minimize configuration concerns while creating Spring based applications. Most of the application can be preconfigured using Spring team's "opinionated view" of the best configuration and use of the Spring platform and third-party libraries.

References

  1. Crossley, Allistair. "Apache Tomcat 8 (8.0.44) - Tomcat Web Application Deployment". Apache Software Foundation . Retrieved 2017-06-27.
  2. Hunter, Jason (1999-10-15). "What's New in Java Servlet API 2.2?". JavaWorld . Retrieved 2020-11-08.
  3. "Web Application Lifecycle". The Java EE 6 Tutorial. Oracle.
  4. "Deploying on a running Tomcat server". Apache Software Foundation.