tags:

views:

19

answers:

1

I am using the jar task in ant and wish to exclude a certain directory. The structure of the directories is something like:

food
 |_ fruits
     |_ apples
     |_ bananas

(having been made generic and simplified a little)

And I have an ant task like this:

<jar destfile="Dest.jar">
    ...
    <fileset dir="food">
            <exclude name="**/bananas/" />
            <exclude name="**/*Test*" />
            <include name="**/*.class" />
    </fileset>
    ...

What I am trying to do is:

  • include all files which end in ".class" (this works)
  • exclude all files which have "Test" in their file name (this works)
  • exclude an entire directory named "bananas" (this doesn't work)

I have tried several combinations of wildcards in trying to exclude the bananas directory, to no avail. I have also tried reordering the include and excludes, though I have no idea if that makes a difference. I've also tried a couple of other suggestions[1][2] which didn't do the job. My wild guess at the moment is that within the bananas directory, there are files which match "*.class", so I'm thinking their inclusion is preventing bananas from being excluded.

NB: I'm matching the real name of the bananas directory exactly, so case-sensitivity shouldn't be an issue. If it can make the task simpler, I can reference the full path to the directory, though I'd prefer to be a bit more refactor-friendly in the ant task.

How can I exclude a directory which is already included in an ant fileset?


[1] http://www.velocityreviews.com/forums/t146608-in-ant-how-do-you-exclude-a-directory-from-copy-or-zip.html
[2] Ant/filesetwithexclude.htm">http://www.java2s.com/Tutorial/Java/0520_Ant/filesetwithexclude.htm

A: 

I've discovered the cause of the problem, and it was nothing to do with how the ant task was written.

The problem seemingly had nothing to do with the fileset includes and excludes, and more to do with whether the jar file was actually being created or not. Having run the task repeatedly, and always using the same destination for the jar, it seems that the created jar file did not replace the existing jar (as I had assumed it would). Deleting the jar and re-running the ant task produced the results I expected.

I don't know if I should feel silly for assuming the file would be replaced, or if I'm right to feel aggrieved there was no log message about it, comments welcome. Anyhoo, problem solved.

Grundlefleck
Odd, I would have expected a log message too. Out of curiousity, are you running ant with the -verbose flag (http://ant.apache.org/problems.html#Examine%20Debug%20Output)? It has always helped me out when I get stuck with a build script.
Pat