How do I create a war file using the jar command?
Author: Deron Eriksson
Description: This tutorial describes how to create a web archive (war) file using the jar command.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0) || Tomcat 5.5.20

Page:    1 2 >

JavaSW web applications are usually packaged in the form of web archive (war) files or enterprise archive (ear) files. This tutorial will show you how you can use the jarW command to build a warW file.

In EclipseSW, I'll start by creating a 'web-archive-test' project as a demonstration project.

Creating 'web-archive-test' project

I'll set the output folder to be web/WEB-INF/classes, since WEB-INF/classes is the standard web archive location for *.class files. Eclipse will automatically compile your *.java files to *.class files.

Below, I set the default output folder location for projects created by the New Java Project wizard. In general, you would be more likely to set it for an individual project via the Project properties, but this demonstrates that you can do it this way too.

Setting default output folder

I created a basic servletW and jspW for this project. I included a jar file in the WEB-INF/lib directory, since this is the standard web archive location for jar files packaged in the web archive.

Project has a servlet, a jsp, and a jar file

Now, I'll open a command prompt window and navigate to my project's web folder. In this location, I'll execute the following jar command:

jar cvf web-archive-test.war .

The results of this command are shown here:

jar cvf web-archive-test.war .

(Continued on page 2)

Page:    1 2 >