Reputation: 17027
I have several JAR file pattern sets, like
<patternset id="common.jars">
<include name="external/castor-1.1.jar" />
<include name="external/commons-logging-1.2.6.jar" />
<include name="external/itext-2.0.4.jar" />
...
</patternset>
I also have a 'war' task containing a lib element:
<lib dir="${src.dir}/jars">
<patternset refid="common.jars"/>
<patternset refid="web.jars"/>
...
</lib>
Like this however, I end up with WEB-INF/lib containing the subdirectories from my patterns:
WEB-INF/lib/external/castor-1.1.jar
WEB-INF/lib/external/...
Is there any way to flatten this, so the JAR files appear at the top-level under WEB-INF/lib, regardless of the directories specified in the patterns? I looked at mapper
but it seems you cannot use them inside lib
.
Upvotes: 3
Views: 2577
Reputation: 4112
I was dissatisfied with having to manually generate a WAR directory or declare library subdirectories, so I came up with this. Seems to work, obviously you'll need to adjust it to your own needs:
<war destfile="build/output.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}" />
<mappedresources>
<fileset dir="${lib.dir}" includes="**/*.jar" />
<chainedmapper>
<flattenmapper/>
<globmapper from="*.jar" to="WEB-INF/lib/*.jar" />
</chainedmapper>
</mappedresources>
</war>
Upvotes: 9
Reputation: 5111
You can try to use mappedresources element (Ant 1.8+)
<mappedresources>
<!-- Fileset here -->
<globmapper from="external/*.jar" to="*.jar"/>
</mappedresources>
http://ant.apache.org/manual/Types/resources.html#mappedresources
If you have a typical web project it is better to split the web-app libraries and general-purpose libraries in different folders and leave WEB-INF/lib to have only those needed at runtime. This way you'll avoid collisions and also your project will look much clearer to other developers.
Upvotes: 4