Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include directory in WAR using Ant

Tags:

ant

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>
like image 215
udeleng Avatar asked Jan 17 '23 20:01

udeleng


1 Answers

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).

like image 71
sudocode Avatar answered Jan 21 '23 15:01

sudocode