EAR application packaging / deployment -- Part II. (war module)

Standard structure for ejb-jar module:


project-war.war
+- WEB-INF
   +- lib
   +- classes
      +- <class-hierarchy>
   +- web.xml
+- <files visible from the web container>

My sample eclipse directory hierarchy:


project-war
+- src (dir for sources)
+- build (dir for compiled classes)
+- dist (dir for packaged module)
+- etc
   +- web.xml
+- web (files visible from the web container: html, jsp, css, etc.)
+- build.xml

Sample web.xml:
[code]
<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="war" version="2.5">

web test

HelloServlet
hu.shining.test.web.HelloServlet

HelloServlet
/hello

index.jsp

[/code]

Sample build.xml for packaging war module:


<project name="web" basedir="." default="package">
    <property name="src.dir" location="src" />
    <property name="build.dir" location="build" />
    <property name="dist.dir" location="dist" />
    <property name="etc.dir" location="etc" />
    <property name="web.dir" location="web" />
    <property name="parent-lib.dir" location="../../lib" />

    <target name="clean">
        <delete dir="${build.dir}" quiet="true" />
        <delete dir="${dist.dir}" quiet="true" />
    </target>

    <target name="init">
        <mkdir dir="${build.dir}" />
        <mkdir dir="${dist.dir}" />
    </target>

    <target name="compile">
        <javac srcdir="${src.dir}" destdir="${build.dir}">
            <classpath>
              <pathelement location="${parent-lib.dir}/javaee.jar"/>
              <pathelement location="../ejb/dist/ejb.jar"/>
            </classpath>
        </javac>
    </target>

    <target name="package" depends="clean, init, compile">
        <war destfile="${dist.dir}/web.war" webxml="${etc.dir}/web.xml">
          <fileset dir="${web.dir}" />
          <classes dir="${build.dir}" />
        </war>
    </target>
</project>