9
votes

I'm using ant to build my web-app. I'm sure this is simple but I can't figure out how to tell ant to create a specific folder in the WEB-INF directory and copy files to it.

My ant war task looks like this:

<target name="warItUp" depends="compile">
    <war destfile="MyApp.war" webxml="${home.dir}\WEB-INF\web.xml">

        <classes dir="${classes.dir}"/>
        <classes file="${src.dir}/hibernate.cfg.xml"/>
        <classes dir="${src.dir}" includes="**/*.hbm.xml"/>

        <!-- Include the PDF files -->
        <fileset dir="${home.dir}/PDFs">
            <include name="**/*.pdf"/>
        </fileset>

        <!-- Include the JSP files -->
        <fileset dir="${home.dir}/JSPs">
            <include name="**/*.jsp"/>
        </fileset>

        <!-- Include the images -->
        <fileset dir="${home.dir}/images">
            <include name="**/*"/>
        </fileset>          
    </war>

All the fileset elements work i.e. they include the pdf, jsp and image files in the root directory of the war file.

But if I want to create a sub-directory in the WEB-INF directory of the war file and include files in it how do I specify that? e.g. say I wanted to include WEB-INF/TagLibraryDescriptors/MyTagLib.tld in the war file or if I wanted to create a WEB-INF/JSP folder in my war file and copy all JSP files to it.

Thanks.

4
Found a solution myself, see answer below. Sorry for wasting anyone's time.CodeClimber

4 Answers

15
votes

OP here, thanks for all the responses. I found another solution - there is a webinf element that can be included in the war task.

This will copy files from the source JSPs folder into the WEB-INF folder in the war file:

<webinf dir="${home.dir}/JSPs" 
includes="**/*.jsp">
</webinf>

whereas this will copy files from the source JSPs folder into the WEB-INF/JSPs folder (my preferred choice):

<webinf dir="${home.dir}" 
includes="/JSPs/**/*.jsp">
</webinf>

I think I'll stick with this solution but thanks for the responses.

6
votes

As an alternative to the nested webinf element, you can also use the zipfileset element, which lets you specify the source folder and the path prefix in the archive:

<zipfileset dir="${home.dir}/JSPs" includes="**/*.jsp" prefix="WEB-INF/JSPs"/>
1
votes

Try to create this directory into your project and then just add fileset like the following:

<fileset dir="${home.dir}/WEB-INF/mydirectory/*">
            <include name="**/*"/>
</fileset>          
0
votes

Why not creating the dir structure you need the mkdir way?