How do I perform Ant path mapping on a war task?

I have several sets of JAR file templates 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>

      

As with this, I end up with WEB-INF / lib containing subdirectories from my templates:

WEB-INF/lib/external/castor-1.1.jar
WEB-INF/lib/external/...

      

Is there a way to iron out this so that JAR files appear at the top level in the WEB-INF / lib section, regardless of the directories specified in the templates? I looked at mapper

but it seems like you can't use them internally lib

.

+2


a source to share


2 answers


You can try using 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 best to split your web application libraries and general purpose libraries in different folders and leave WEB-INF / lib only those that are needed at runtime. This way you avoid collisions, and your project looks much clearer to other developers.

+3


a source


I was unhappy with having to manually generate a WAR directory or declare library subdirectories, so I came up with this. It seems like it needs to work, obviously you will need to customize 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>

      

+9


a source







All Articles