How do I specify the files to include in a WAR file?
I need to create a WAR file that just contains static content files (gifs, jpgs, html, js, etc). I have a directory structure that contains all the files and need to create the WAR file via an ANT (1.5.1) build task. Right now I just have this in the ANT task:
<war destfile="${output.file}" webxml="WEB-INF/web.xml" basedir="${basedir}">
&l开发者_如何学Pythont;fileset dir="${basedir}/sales" />
</war>
The files I want to include are in C:/basedir/sales and its subdirectories. When I try to run this task I get "A zip file cannot include itself". So clearly putting that fileset in there is not the right way to do it. I am unclear as to what I need to put in the task and in the web.xml file to specify what files to include within the archive.
I think the basedir="${basedir}" is causing you the problems. Also, I think the way you have it written will require that web.xml exist inside WEB-INF dir relative to where you run ant from.
So, try creating /WEB-INF/web.xml as follows:
<?xml version="1.0" encoding="utf-8" ?>
<web-app>
</web-app>
Then try updating /build.xml as follows:
<?xml version="1.0" encoding="UTF-8"?>
<project name="yourproject" basedir="." default="war" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="war" description="--> build war file">
<war destfile="./mywar.war" webxml="WEB-INF/web.xml">
<fileset dir="C:/basedir/sales" />
</war>
</target>
</project>
Then you should be able to run "ant war" from command line and it should create "mywar.war" in your current directory.
精彩评论