Using ant military task to include files in the WEB-INF directory

I use ant to build my web application. I am sure it is simple, but I cannot figure out how to tell ant to create a specific folder in the WEB-INF directory and copy the files there.

My ant military task is as follows:

<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 elements of the file set work, that is, they include pdf, jsp and image files in the root directory of a military file.

But if I want to create a subdirectory in the WEB-INF directory of a military file and include files in it, how can I indicate this? for example, for example, I wanted to include WEB-INF / TagLibraryDescriptors / MyTagLib.tld in a military file, or if I wanted to create a WEB-INF / JSP folder in my military file and copy all the JSP files there.

Thanks.

+7
source share
4 answers

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

This will copy the files from the JSP source folder to the WEB-INF folder in the war file:

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

whereas this will copy the files from the original JSP folder to the WEB-INF / JSP folder (my preferred choice):

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

I think I will stick to this decision, but thanks for the answers.

+14
source

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

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

Try creating this directory in your project, and then just add a set of files, for example:

 <fileset dir="${home.dir}/WEB-INF/mydirectory/*"> <include name="**/*"/> </fileset> 
+1
source

Why not create a dir structure, do you need a mkdir method?

0
source

All Articles