Take the 2-minute tour ×

I converted a custom (previously working, of course) Ant task of ours from using <zipfileset> as the only way to reuse groups of resources between a <zip> task and our custom task turned out to be to use resource collections. So essentially, instead I now just have <fileset> wrapped by <mappedresources>.

<project name="test" default="installers">
  <target name="installers">
    <union id="common">
      <fileset prefix="." dir="." includes="1"/>
        <fileset dir="." includes="2"/>
        <globmapper from="*" to="3/*"/>
      <resources refid="common"/>

The custom task looks like this, omitting all the WiX-specific crap as it's not the problem (or at least it's not the problem right now.)

public class GenerateWixTask extends Task {
    private Resources resources;

    public void execute() throws BuildException {
        // omitting root element setup

        Iterator<?> resourceIterator = resources.iterator();
        while (resourceIterator.hasNext()) {
            Resource resource = (Resource) resourceIterator.next();

            // This is the relative path with respect to the WiX install.
            File filePath = new File(resource.getName());
            //String fileName = filePath.getName();

            // This is the file which will be used as the actual data.
            //TODO: How to get this?

            System.out.println("resource: " + resource.getName());
            System.out.println("  which is a " + resource.getClass());
            System.out.println("  name = " + resource.getName());
            System.out.println("  location = " + resource.getLocation());

            FileProvider provider = (FileProvider) resource.as(FileProvider.class);
            if (provider != null) {
                System.out.println("  file = " + provider.getFile());


        // omitting code to write the XML

    public void setResourcesref(Reference resourcesref) {

    public Resources createResources() {
        if (resources == null) {
            resources = new Resources();
        return resources;

The output this gives me is as follows:

[generatewix] resource: 1
[generatewix]   which is a class org.apache.tools.ant.types.resources.FileResource
[generatewix]   name = 1
[generatewix]   location =
[generatewix]   file = C:\Data\test\1
[generatewix] resource: 3/2
[generatewix]   which is a class org.apache.tools.ant.types.resources.MappedResource
[generatewix]   name = 3/2
[generatewix]   location =

On reading the source code for MappedResource, FileProvider is handled specially to hide the source file (the comment makes it sound like it's to prevent abuse... I'm not exactly trying to abuse it.) But I do want to find out the path to the file, because I'm writing an XML file for another application to read...

Is there a workaround for this?

share|improve this question

1 Answer 1

It's obvious that mapped path can't be source for real File. And MappedResource is not FileResource.

Try just reading data from getInputStream() and writing it to new path specified by getName().

share|improve this answer
I'm trying to avoid doing unnecessary file I/O... otherwise I would just copy all the resources into another directory and just use that directory as a single fileset. Our installers are nearing 200MB and copying all of them was unnecessarily increasing the build time. –  Trejkaz Oct 17 '12 at 12:18

Your Answer


