4
votes

I am building a war file using ANT and I want to include the src directory into the war file. When I use the fileset element, only the content of that folder is included. I want the src directory to be included into the WEB-INF folder. I don't want to copy the sources to the WEB-INF folder on disk. Ant properly includes the jars from my lib directory into WEB-INF/lib without copying them in my project.

So I will have something like this:

/WEB-INF
/WEB-INF/src
/WEB-INF/classes
/WEB-INF/lib
/META-INF

The target looks like this:

<target name="war" depends="init">
    <war destfile="dist/web.war" webxml="WebContent/WEB-INF/web.xml">
        <fileset dir="WebContent"/>
        <lib dir="WebContent/WEB-INF/lib"/>
        <lib dir="lib"/>
        <classes dir="build/classes"/>
        <classes dir="config"/>
    </war>
</target>
1

1 Answers

9
votes

I assume you were trying to include src something like this:

<fileset dir="src"/>

It should work if you use this:

<fileset dir="." includes="src/**"/>

If you need to put a file or dir to a specific path in the war, you can use zipfileset instead and its prefix attribute, e.g.

<zipfileset dir="." includes="src/**" prefix="WEB-INF"/>

(See also examples in the war task documentation, which include usage of zipfileset).