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.
More information: Manually Creating a Simple WAR File
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".
/application
will allow your application to be accessed as such:
http://www.myserver.com/applicationWEB-INF/classes folder and place your servlet
classes into it, keeping the package sub-folders intact.WEB-INF/lib folder and place elements.jar, openviz2.jar
and jimi.jar plus any additional JAR files into it.jar command to create your WAR file e.g. jar cfM myapp.war *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 WAR file (included files other than web.xml have been given zero-length to reduce the size).