ant mixes up file hierarchy within war file

W

Werner Butscher

Hello everyone,

I use ant for building my jar and war files. Since I added two
property files directly to the WEB-INF directory of my servlet, the
war file is not packed correctly anymore.

My directoy structure should be like this:

/META-INF
/WEB-INF
classes/
lib/
web.xml
log4j.properties
database.props

The problem is, the last two files will be packed directly at root
level instead at /WEB-INF

I tried all combinations of filesets, patternsets, revied older build
files etc but could not find the reason. The target in the current
build file looks like this:

(where build.dir is WEB-INF)

<target name="war" depends="compile">
<delete dir="${war.dir}"/>
<mkdir dir="${war.dir}"/>
<war warfile="${war.dir}/${project}.war"
webxml="${build.dir}/web.xml">
<fileset dir="${build.dir}">
<exclude name="web.xml"/>
<exclude name="**/*.bak"/>
<exclude name="**/*.class"/>
<exclude name="**/*.java"/>
<exclude name="lib/"/>
<exclude name="classes/"/>
<include name="**/*.props"/>
<include name="**/*.properties"/>
</fileset>
<classes dir="${build.dir}/classes"/>
<lib dir="${lib.dir}">
<include name="*.jar"/>
</lib>
<lib dir="${servletlibs.dir}">
<include name="*.jar"/>
</lib>
<lib dir="${cmlib.dir}">
<include name="*.jar"/>
</lib>
<lib dir="${cmclasses.dir}">
<include name="*.jar"/>
</lib>
</war>
</target>

I also checked the compile task and removed it, still the same, the
problem must be somewhere here...

Any help would be appreciated... :-}

Werner
 
O

Oscar kind

Werner Butscher said:
I use ant for building my jar and war files. Since I added two
property files directly to the WEB-INF directory of my servlet, the
war file is not packed correctly anymore.

My directoy structure should be like this:

/META-INF
/WEB-INF
classes/
lib/
web.xml
log4j.properties
database.props

The problem is, the last two files will be packed directly at root
level instead at /WEB-INF [...]

(where build.dir is WEB-INF)

<target name="war" depends="compile">
<delete dir="${war.dir}"/>
<mkdir dir="${war.dir}"/>
<war warfile="${war.dir}/${project}.war"
webxml="${build.dir}/web.xml">
<fileset dir="${build.dir}">
<exclude name="web.xml"/>
<exclude name="**/*.bak"/>
<exclude name="**/*.class"/>
<exclude name="**/*.java"/>
<exclude name="lib/"/>
<exclude name="classes/"/>
<include name="**/*.props"/>
<include name="**/*.properties"/>
</fileset>

Instead of a fileset, use a zipfileset and specify the "prefix" attribute.
With it, you can specify the subdirectory to place the files in.
 
W

Werner Butscher

great, this worked, thankyou:

<war destfile="${war.dir}/${project}.war" webxml="${build.dir}/web.xml">
<zipfileset dir="${build.dir}" prefix="WEB-INF" >
<exclude name="web.xml"/>
<exclude name="**/*.bak"/>
<exclude name="**/*.class"/>
<exclude name="**/*.java"/>
<exclude name="lib/"/>
<exclude name="classes/"/>
<include name="database.props"/>
<include name="log4j_servlet.properties"/>
</zipfileset>
<classes dir="${build.dir}/classes"/>
<lib dir="${lib.dir}">
<include name="*.jar"/>
</lib>
<lib dir="${servletlibs.dir}">
<include name="*.jar"/>
</lib>
<lib dir="${cmlib.dir}">
<include name="*.jar"/>
</lib>
<lib dir="${cmclasses.dir}">
<include name="*.jar"/>
</lib>
</war>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top