tags:

views:

326

answers:

1

I need to create a WAR file that just contains static content files (gifs, jpgs, html, js, etc). I have a directory structure that contains all the files and need to create the WAR file via an ANT (1.5.1) build task. Right now I just have this in the ANT task:

<war destfile="${output.file}" webxml="WEB-INF/web.xml" basedir="${basedir}">
    <fileset dir="${basedir}/sales" />       
</war>

The files I want to include are in C:/basedir/sales and its subdirectories. When I try to run this task I get "A zip file cannot include itself". So clearly putting that fileset in there is not the right way to do it. I am unclear as to what I need to put in the task and in the web.xml file to specify what files to include within the archive.

+1  A: 

I think the basedir="${basedir}" is causing you the problems. Also, I think the way you have it written will require that web.xml exist inside WEB-INF dir relative to where you run ant from.

So, try creating /WEB-INF/web.xml as follows:

<?xml version="1.0" encoding="utf-8" ?>

<web-app>
</web-app>

Then try updating /build.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>
<project name="yourproject" basedir="." default="war" xmlns:ivy="antlib:org.apache.ivy.ant">
        <target name="war" description="--> build war file">
                <war destfile="./mywar.war" webxml="WEB-INF/web.xml">
                    <fileset dir="C:/basedir/sales" />
                </war>
        </target>
</project>

Then you should be able to run "ant war" from command line and it should create "mywar.war" in your current directory.

Dave Paroulek
basedir is defined in the project as ../.., the build is run via a .cmd script that is located at C:/basedir/build/ant so ../.. is correctly referencing C:/basedir...project is defined as <project name="example" default="war" basedir="../..">.
Brian Schroth
I found that my errors were being caused by an entirely different problem, and the syntax here was fine. Thanks for the help.
Brian Schroth