IAmYourFaja
IAmYourFaja

Reputation: 56944

Ant: using war task on exploded directory

I am relatively new to Ant, and am trying to find the easiest way to WAR-up my web application.

I already have build targets that create the following "exploded WAR" directory structure:

MyApp/
    src/
        ...
    gen/    <-- this gets created as a part of every build
        war/
            stylesheets/
                myapp.css
            views/
                index.jsp
                cool.jsp
                ...
            WEB-INF/
                web.xml
                lib/
                    (All of my dependencies)
                classes/
                    META-INF/
                        jdoconfig.xml
                    com/
                        myapp/
                            (All compiled binaries)

So, given the fact that by the time I'm ready to create the WAR file (using <war/>, <zip/> or anything else), I already have the exploded version of the WAR ready to go.

The problem I have with the <war/> task is that it doesn't seem to support directories under war/ besides WEB-INF/lib and WEB-INF/classes:

<war destfile="myapp.war" webxml="gen/war/WEB-INF/web.xml">
    <lib dir="gen/war/WEB-INF/lib" />
    <classes dir="gen/war/WEB-INF/classes" />
</war>

What about stylesheets and views, or anything else I might want? What if I want to add a file or directory to WEB-INF/? What if I wanted to add something to the war at the same level as WEB-INF/? The <war/> task just seems to be too inflexible.

Either way (as I'm sure the task is flexible and I'm just not "getting" it), I just want the easiest way to create a myapp.war with the exact directory structure that the earlier build targets have created under gen/war. Thanks in advance.

Upvotes: 2

Views: 1332

Answers (2)

IAmYourFaja
IAmYourFaja

Reputation: 56944

Figured it out, this is way easier. The <war/> task imposes too many constraints if you already have your own exploded war directory. Just zip it up!

<zip destfile="myapp.war"
    basedir="gen/war" update="true" />

Upvotes: 1

user1981604
user1981604

Reputation: 41

You can use a fileset inside of the war tag

An Example from our build file

<war destfile="${war.dest.file.name.without.extension}.war"      manifest="${build.dir}/MANIFEST.MF" webxml="${webcontent.dir}/WEB-INF/web.xml">
        <fileset dir="${webcontent.dir}" casesensitive="no">
            <exclude name="WEB-INF/lib/**"/>
            <exclude name="WEB-INF/classes/**"/>
            <exclude name="WEB-INF/web.xml"/>
            <exclude name="META-INF/context.xml"/>
         </fileset>
         <lib dir="${app.lib.dir}"/>
         <classes dir="${classes.dir}"/>
    </war>

Upvotes: 3

Related Questions