如何排除已包含在 Ant 文件集中的目录?

发布于 2024-09-10 13:09:21 字数 1350 浏览 8 评论 0原文

我正在 ant 中使用 jar 任务,并希望排除某个目录。目录的结构类似于:(

food
 |_ fruits
     |_ apples
     |_ bananas

已变得通用并简化了一点)

我有一个像这样的ant任务:

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

我想做的是:

  • 包含所有以“.class”结尾的文件(这有效)
  • 排除文件名中包含“Test”的所有文件(这有效)
  • 排除名为“bananas”的整个目录(这不起作用

我尝试了几种通配符组合来尝试排除香蕉目录,无济于事。我也尝试过重新排序包含和排除,但我不知道这是否会产生影响。我还尝试了其他一些建议[1][2],但没有成功。我目前的疯狂猜测是,在bananas目录中,有一些与“*.class”匹配的文件,所以我认为它们的包含会阻止香蕉被排除。

注意:我完全匹配香蕉目录的真实名称,因此区分大小写不应该成为问题。如果它可以使任务更简单,我可以引用目录的完整路径,尽管我更喜欢在 ant 任务中更加重构友好。

如何排除已包含在 ant 文件集中的目录?


[1] http://www.velocityreviews.com/forums/t146608-in-ant-how-do-you -从-copy-or-zip.html中排除a-directory-from-copy-or-zip.html
[2] http://www.java2s.com/Tutorial/Java/0520__Ant /filesetwithexclude.htm

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] http://www.java2s.com/Tutorial/Java/0520__Ant/filesetwithexclude.htm

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰之心 2024-09-17 13:09:22

我已经找到了问题的原因,这和ant任务的写法无关。

该问题似乎与文件集包含和排除无关,更多地与 jar 文件是否实际创建有关。重复运行该任务,并且始终使用相同的 jar 目标,似乎创建的 jar 文件没有替换现有的 jar(正如我所假设的那样)。删除 jar 并重新运行 ant 任务产生了我预期的结果。

我不知道我是否应该因为假设文件将被替换而感到愚蠢,或者我是否应该感到委屈,因为没有关于它的日志消息,欢迎评论。无论如何,问题解决了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文