# Ant User Manual

## War

### Description

An extension of the Jar task with special treatment for files that should end up in the `WEB-INF/lib`, `WEB-INF/classes` or `WEB-INF` directories of the Web Application Archive.

(The War task is a shortcut for specifying the particular layout of a WAR file. The same thing can be accomplished by using the prefix and fullpath attributes of zipfilesets in a Zip or Jar task.)

The extended zipfileset element from the zip task (with attributes prefix, fullpath, and src) is available in the War task.

### Parameters

Attribute | Description | Required
warfile | the war-file to create. | Yes
webxml | The deployment descriptor to use (WEB-INF/web.xml). | Yes
basedir | the directory from which to jar the files. | No
compress | Not only store data but also compress them, defaults to true | No
includes | comma separated list of patterns of files that must be included. All files are included when omitted. | No
includesfile | the name of a file. Each line of this file is taken to be an include pattern | No
excludes | comma separated list of patterns of files that must be excluded. No files (except default excludes) are excluded when omitted. | No
excludesfile | the name of a file. Each line of this file is taken to be an exclude pattern | No
defaultexcludes | indicates whether default excludes should be used or not ("yes"/"no"). Default excludes are used when omitted. | No
manifest | the manifest file to use. | No
whenempty | Behavior to use if no files match. | No

### Nested elements

#### lib

The nested `lib` element specifies a FileSet. All files included in this fileset will end up in the `WEB-INF/lib` directory of the war file.

#### classes

The nested `classes` element specifies a FileSet. All files included in this fileset will end up in the `WEB-INF/classes` directory of the war file.

#### webinf

The nested `webinf` element specifies a FileSet. All files included in this fileset will end up in the `WEB-INF` directory of the war file. If this fileset includes a file named `web.xml`, the file is ignored and you will get a warning.

### Examples

Assume the following structure in the project's base directory:

    thirdparty/libs/jdbc1.jar
    thirdparty/libs/jdbc2.jar
    build/main/com/myco/myapp/Servlet.class
    src/metadata/myapp.xml
    src/html/myapp/index.html
    src/jsp/myapp/front.jsp
    src/graphics/images/gifs/small/logo.gif
    src/graphics/images/gifs/large/logo.gif

then the war file `myapp.war` created with

    <war warfile="myapp.war" webxml="src/metadata/myapp.xml">
      <fileset dir="src/html/myapp"/>
      <fileset dir="src/jsp/myapp"/>
      <lib dir="thirdparty/libs">
        <exclude name="jdbc1.jar"/>
      </lib>
      <classes dir="build/main"/>
      <zipfileset dir="src/graphics/images/gifs"
                  prefix="images"/>
    </war>

will consist of

    WEB-INF/web.xml
    WEB-INF/lib/jdbc2.jar
    WEB-INF/classes/com/myco/myapp/Servlet.class
    META-INF/MANIFEST.MF
    index.html
    front.jsp
    images/small/logo.gif
    images/large/logo.gif

using Ant's default manifest file. The content of `WEB-INF/web.xml` is identical to `src/metadata/myapp.xml`.

Copyright © 2000,2001 Apache Software Foundation. All rights Reserved.