WAR File Format (Sun) - Content and Structure

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.

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 URL request will be routed. 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. Advantages of WAR files:

  • easy development, testing and deployment
  • the version of the deployed application is easily identified
  • all J2EE containers support .WAR files

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.

The following sample web.xml file demonstrates how a servlet is declared and associated.

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's 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.

Read more about this topic:  WAR File Format (Sun)

Famous quotes containing the words content and/or structure:

    The Republican convention, an event with the intellectual content of a Guns’n’Roses lyric attended by every ofay insurance broker in America who owns a pair of white shoes.
    —P.J. (Patrick Jake)

    Just as a new scientific discovery manifests something that was already latent in the order of nature, and at the same time is logically related to the total structure of the existing science, so the new poem manifests something that was already latent in the order of words.
    Northrop Frye (b. 1912)