OpenViz Elements - Java - WAR File

Introduction

A WAR file assists the Java server administrator in deploying a server-based application. It has the same format as a JAR file but has an additional manifest which instructs the application server how to map a particular URL to an application and which servlet class to run. When a WAR file is placed in the server's root folder, it is automatically extracted and prepared for use.

Prerequisites

  1. A Java application server such as Apache Tomcat, Netscape iPlanet or Macromedia JRUN must be used.

More information: Manually Creating a Simple WAR File

OpenViz considerations

In addition to the HTML, JAR, class, servlet and/or JSP files which make up the application, a so-called deployment descriptor file must be created and included in the WAR file. The descriptor provides information to the application server about how to map a particular URL to the application, which servlet class to run plus additional per-application configuration parameters. It is named web.xml and must be placed in the WEB-INF sub-directory of the WAR file. An example descriptor is displayed below:

<?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>IntroApp</servlet-name>
    <servlet-class>com.avs.IntroApp</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>IntroApp</servlet-name>
    <url-pattern>/IntroApp</url-pattern>
  </servlet-mapping>
</web-app>

The <servlet-mapping> section instructs the server that any URL containing the pattern "/IntroApp" should use the IntroApp servlet. The <servlet> section indentifies the class containing the IntroApp servlet as "com.avs.IntroApp".

Step-by-step

  1. Build your servlet classes.
  2. Create a WEB-INF folder and in it a new file called web.xml, using the template above.
  3. Modify the <servlet-name> fields to the name of your application.
  4. Modify the <url-pattern> field to the folder you wish your application to be referenced under e.g. entering /application will allow your application to be accessed as such: http://www.myserver.com/application
  5. Modify the <servlet-class> field to your main servlet class.
  6. Create a WEB-INF/classes folder and place your servlet classes into it, keeping the package sub-folders intact.
  7. Copy any static HTML and JSP files into the root folder.
  8. Create a WEB-INF/lib folder and place elements.jar, openviz2.jar and jimi.jar plus any additional JAR files into it.
  9. Use the jar command to create your WAR file e.g. jar cfM myapp.war *
  10. Place your WAR file into the root folder of your application server where it will be extracted and run.

In summary, the WAR file should have the following example layout:

index.html
application.jsp
image.gif
other.files
WEB-INF/web.xml
WEB-INF/lib/elements.jar
WEB-INF/lib/openviz2.jar
WEB-INF/lib/jimi.jar
WEB-INF/lib/other.jar
WEB-INF/classes/com/company/MyServlet.class

Example

Example WAR file (included files other than web.xml have been given zero-length to reduce the size).