Clever Geek Handbook
📜 ⬆️ ⬇️

WAR (file type)

Web Archive or Web Application Resource [1] is a file format that describes how a complete web application is packaged according to the specification of Java servlets into a file in JAR or ZIP format . [2] Such files have the extension “ .war ” and therefore are also called “WAR files”.

Web archive
Expansion.war
DeveloperSun microsystems
Format type
ContainsJSP , Java Servlets
Expanded from

Benefits of WAR files:

  • ease of development, testing and deployment
  • easy to identify version of deployed application
  • All J2EE containers support WAR files

Structure

The following example shows the structure of a Web Archive .

  /index.html
 /guestbook.jsp
 /images/logo.png
 /WEB-INF/web.xml
 /WEB-INF/classes/org/wikipedia/Util.class
 /WEB-INF/classes/org/wikipedia/MainServlet.class
 /WEB-INF/lib/util.jar
 /META-INF/MANIFEST.MF

Please note that in the WEB-INF there is a so-called Deployment Descriptor named web.xml that defines all servlets and other properties of the Web application. If the application contains only JSP files, this file is not strictly required.

An example web.xml deployment descriptor demonstrating the servlet specification:

  <? 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 located in the classpath of ClassLoader . These java files with the extension .class will be loaded when the web application loads and starts to run. Any JAR files located in the / WEB-INF / lib directory will also be placed in the classpath .

Creation

You can create a WAR archive:

  • packer included in the J2EE SDK.
  • By completing the "war" task in Apache Ant .
  • By running the mvn clean install command in Apache Maven .
  • JAR utility included in J2SE. You only have to make sure that the directory structure of your application matches the one required for the WAR format. Just run the following command in the root directory of your application:
  jar cvf archiveName.war.

Application

All J2EE containers support WAR files.

In order for the web container (web server) to be able to read the deployment descriptor and start redirecting requests to this application, you must deploy the deploy file to the container. One of the deployment options is to copy the WAR file into the autodeploy directory of the web container.

A WAR can be digitally signed in the same way as a JAR file to verify the authenticity of the code.

Applications installed from WAR files on one server cannot use each other's resources; their execution is isolated. However, they can use shared server libraries (for example, at Tomcat they are located in $ {catalina.base} / lib), but such libraries cannot be installed using the war file.

Notes

  1. ↑ Apache Tomcat 9 - Tomcat Web Application Deployment
  2. ↑ Danny Coward, Yutaka Yoshida: Java ™ Servlet Specification, Version 2.4. Archived January 7, 2010. 24. November 2003

See also

  • EAR
  • Jar
  • .EXE
Source - https://ru.wikipedia.org/w/index.php?title=WAR_(file_type)&oldid=100186869


More articles:

  • Ceratites
  • Nikolay Sologubov Club
  • Diffusion Coefficient
  • Berezhnoy, Nikolai Ivanovich (Hero of the Soviet Union)
  • Risotto
  • Blinder Game
  • Victoria River Downs (Airport)
  • Vernazul
  • 4th Guards Military Base
  • Lubier

All articles

Clever Geek | 2019