Developing Web Applications With Ant by Richard Hightower - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Using the War Task to Create a WAR File

Ant defines a special task for building Web Archive (WAR) files. The war task defines two special file sets for classes and library JAR files: classes and lib, respectively. Any other file set would be added to the document root of the WAR file (see Chapter 6 for more information).

Listing 20.8 uses the war task with three file sets. The war task will put the files specified by the fileset into the document root. As you can see in Listing 20.8, one file set includes the helloapplet.jar file, and the other two file sets contain all the files in the HTML and JSP directories. All three file sets will end up in the docroot of the Web application archive.

The war task body also specifies where Tomcat should locate the classes using the file set called classes

(<classes dir="${build}" />). Files in the classes directory will be added to the WAR file at the docroot/WEB- INF/classes. Similarly, the lib element specifies a file set that will be added to the WAR file's docroot/WEB-

INF/lib directory.

<war warfile="${dist}/hello.war" webxml="${meta}/web.xml"> <!-
Include the html and jsp files.
Put the classes from the build into the classes

directory of the war.
/-->
<fileset dir="./HTML" />
<fileset dir="./JSP" />
<!-- Include the applet. /-->
<fileset dir="${lib}" includes="helloapplet.jar" />

<classes dir="${build}" />
<!-- Include all of the jar files except the ejbeans and applet. The other build files that create jars have to be run in the correct order. This is covered later.

/-->
<lib dir="${lib}" >
<exclude name="greet-ejbs.jar"/>
<exclude name="helloapplet.jar"/>

</lib>
</war>

 

Listing 20.8