So I set up a new project into Eclips开发者_如何学运维e and created a build.xml that creates a war file. The problem that I am having is that the only files that are included in the war are what's in the WEB-INF. How do you include my web folder into the war?
- Project
- src
- web
- WEB-INF
(edited for correctness and clarity)
Assuming Project Setup as follows:
- Project
- src (java source files)
- web (web content)
- WEB-INF (with at least a web.xml inside)
- build (build.xml is here)
Here's a quick ant script to war it up:
<?xml version="1.0"?>
<project name="sample" basedir="../" default="war">
<target name="compile">
<delete dir="build/classes"/>
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes"/>
</target>
<target name="war" depends="compile">
<war destfile="myWar.war" webxml="WEB-INF/web.xml">
<fileset dir="web"/>
<classes dir="build/classes"/>
<webinf dir="WEB-INF"/>
</war>
</target>
</project>
See the Ant user manual for the war
task for more information.
Your WEB-INF should be below the web folder. Classes should go in web/WEB-INF/classes.
Build the finished layout and then use the WAR task to wrap it up.
Since you are referring to a build.xml file, I'll assume you are using Ant (or Eclipse is using it for you.) If that is the case, you want to use the war Ant task and its includes attribute (or fileset nested task) to list your web directory for inclusion in the resulting war.
http://ant.apache.org/manual/Tasks/war.html
Assuming you are using an older Ant distribution that lacks the war task, use the jar task, which war inherits from.
I don't know what your build.xml looks like, but I would venture to guess it has a war or jar task. Using its includes attribute, it should look something like this (this is from the top of my head, you might need to tweak it to compile for your specific situation):
<war destfile="your.war" webxml="src/metadata/your.xml">
<fileset dir="src"/>
<fileset dir="web"/>
<classes dir="build/classes"/>
</war>
Without seeing your build.xml, it is impossible to tell if this suggestion is applicable or not, though.
精彩评论