[英]Using ant war task to include files in WEB-INF directory
I'm using ant to build my web-app. 我正在使用ant构建我的网络应用程序。 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.
我确信这很简单,但我无法弄清楚如何告诉ant在WEB-INF目录中创建一个特定的文件夹并将文件复制到它。
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 ie they include the pdf, jsp and image files in the root directory of the war file. 所有文件集元素都可以工作,即它们包含war文件根目录中的pdf,jsp和image文件。
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? 但是如果我想在war文件的WEB-INF目录中创建一个子目录并在其中包含文件,我该如何指定? eg 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.
例如,我想在war文件中包含WEB-INF / TagLibraryDescriptors / MyTagLib.tld,或者我想在war文件中创建一个WEB-INF / JSP文件夹并将所有JSP文件复制到它。
Thanks. 谢谢。
OP here, thanks for all the responses. OP在这里,感谢所有的回复。 I found another solution - there is a webinf element that can be included in the war task.
我发现了另一个解决方案 - 有一个webinf元素可以包含在war任务中。
This will copy files from the source JSPs folder into the WEB-INF folder in the war file: 这会将源JSPs文件夹中的文件复制到war文件中的WEB-INF文件夹中:
<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): 而这会将文件从源JSPs文件夹复制到WEB-INF / JSPs文件夹(我的首选):
<webinf dir="${home.dir}"
includes="/JSPs/**/*.jsp">
</webinf>
I think I'll stick with this solution but thanks for the responses. 我想我会坚持这个解决方案,但感谢你的回复。
作为嵌套webinf
元素的替代方法,您还可以使用zipfileset
元素,该元素允许您在存档中指定源文件夹和路径前缀:
<zipfileset dir="${home.dir}/JSPs" includes="**/*.jsp" prefix="WEB-INF/JSPs"/>
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>
为什么不创建你需要mkdir方式的目录结构?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.