Recipe 23.10 Packaging a Servlet into a WAR File


You have a servlet and other web resources and want to package them into a single file for deploying to the server.


Use jar to make a web archive (WAR) file.


Servlets are server-side components for use in web servers. They can be packaged for easy installation into a web server. A web application in the Servlet API specification is a collection of HTML and/or JSP pages, servlets, and other resources. A typical directory structure might include the following:

index.html, foo.jsp

Web pages


Server directory




Directory for servlets and any classes used by them or by JSPs


Directory for any JAR files of classes needed by classes in the WEB-INF/classes directory

Once you have prepared the files in this way, you just package them up with jar :

jar cvf MyWebApp.war .

You then deploy the resulting WAR file into your web server. For details on this, consult the web server documentation.

Java Cookbook
Java Cookbook, Second Edition
ISBN: 0596007019
EAN: 2147483647
Year: 2003
Pages: 409
Authors: Ian F Darwin

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: