ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <>
Subject Re: How to reuse a fileset as a Class-Path in a manifest
Date Tue, 08 Nov 2005 19:41:00 GMT
> I'm trying to re-use a fileset pointing to a lib folder containing all of my
> jars as a manifest Class-Path entry for my project.
> [...]
> I don't want to use any complexity or trickery to acheive my result (for
> example a custom task or a script task) but I just don't see any other way.
> I'm hoping to keep my build file relatively simple as I am trying to create
> some standard practices for my team. Is there a better way?

Here's the way to do it using pure Ant.

1) Define a property using the location attribute. This ensure it's

<property name="jar-all" location="acme/jar/all" />

2) Define your fileset. I usually reuse the property above

    <fileset id="jars" dir="${jar-all}">
      <include name="*.jar" />

3) Define the path

    <path id="cp"> <fileset refid="jars" /> </path>

3bis) Convert the path into a String suitable for a Jar's manifest:

    <pathconvert property="classpath" refid="cp"
                 pathsep=" " dirsep="/">
      <map from="${jar-all}" to="all" />

The trick here is to use the "canonical" file name to remove the
absolute path names in your jars, and map it to what you want. Here,
the jar with the in-manifest Class-Path references jars in a all/
subdir, so that's what I map to. The to attribute could also be empty

4) Create the jar

    <jar ...>
        <attribute name="Class-Path" value="${classpath}"/>

But really, I need to put the custom task I have into Ant, because
it's a recurring question. Now that I have a lot of free time on my
hands, I'll do that... --DD

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message