ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Turner <>
Subject Re: wildcarding dir in fileset?
Date Fri, 04 May 2001 11:58:00 GMT
The inventor of the regexp <mapper> type deserves a medal for providing
a solution to this problem.

Let's assume we have this structure:


We want to jar the contents of all the classes together, but do not know
until runtime the names or number of directories under src/.

One almost-solution is to use the "flatten" attribute as follows:

<copy todir="${allclasses}" flatten="true">
  <fileset dir="src">
    <include name="*/classes/**"/>

Ie, move the wildcard to the include, instead of the dir. This will get
the files in the jar, but unfortunately will lose any structure below
the classes/ directory. Eg if you have:

In your jar, you'll just get "A.class" and "B.class" in the root.
However, this flatten trick is useful for things that don't require
directories, eg if we wanted to copy src/*/lib/*.jar

The best solution is, as mentioned, to use the regexp <mapper> type,
found in recent (1.3?) releases of Ant:

<copy todir="dest/">
  <fileset dir="src"/>
    <mapper type="regexp" from=".*/classes/(.*)" to="\1"/>

This will do what we want, and preserve the structure below classes/.

To use the regexp mapper type, you need optional.jar and
jakarta-regexp.jar in your $ANT_HOME/lib directory. The docs describe
this adequately.

I've put together a small demo of the above at



View raw message