ant 如何处理不存在的路径元素?

发布于 2024-09-28 02:25:33 字数 235 浏览 1 评论 0原文

如果我使用指向不存在目录的路径元素定义路径,ant 会如何表现?

<path id="foo.bar">
   <pathelement location="this/might/not/exist/">
</path>

场景是 ant 文件用于多个项目 - 有些项目有这个附加文件夹,有些则没有。

ant 会直接忽略它,还是会失败?

How does ant behave if I define a path with a pathelement which points to a non-existent directory?

<path id="foo.bar">
   <pathelement location="this/might/not/exist/">
</path>

The scenario is that the ant file is used for several projects - some have this additional folder, and some do not.

Does ant just ignore it, or does it fail?

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

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

发布评论

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

评论(1

友欢 2024-10-05 02:25:33

这取决于上下文。

当用作 javac 任务的类路径时,丢失的目录将被简单地忽略:

此任务将删除所有指向不存在的条目
文件/目录从传递给编译器的类路径。

但是,如果您使用包含不存在目录的路径(例如作为副本的源),您将收到错误。
例如,这里存在目录“一”和“三”,但不存在“二”:

<path id="mypath">
    <pathelement path="one" />
    <pathelement path="two" />
    <pathelement path="three" />
</path>

<copy todir="dest">
    <path refid="mypath" />
</copy>

BUILD FAILED
/.../build.xml:14: Warning: Could not find resource file ".../two" to copy.

您可以使用 dirset 来过滤掉丢失的项目:

<pathconvert property="dirs.list" pathsep="," refid="mypath">
    <map from="${basedir}/" to="" />
</pathconvert>
<dirset id="exists.dirs" dir="." includes="${dirs.list}" />    
<copy todir="dest">
    <dirset refid="exists.dirs" />
</copy>

 [copy] Copied 2 empty directories to 2 empty directories under /.../dest

It depends on the context.

When used as a classpath for the javac task, the missing directories are simply ignored:

This task will drop all entries that point to non-existent
files/directories from the classpath it passes to the compiler.

But if you use a path containing a non-existent directory, say as the source for a copy, you'll get an error.
For example, here directories 'one' and 'three' exist, but 'two' does not:

<path id="mypath">
    <pathelement path="one" />
    <pathelement path="two" />
    <pathelement path="three" />
</path>

<copy todir="dest">
    <path refid="mypath" />
</copy>

BUILD FAILED
/.../build.xml:14: Warning: Could not find resource file ".../two" to copy.

You could use a dirset to filter out the missing items perhaps:

<pathconvert property="dirs.list" pathsep="," refid="mypath">
    <map from="${basedir}/" to="" />
</pathconvert>
<dirset id="exists.dirs" dir="." includes="${dirs.list}" />    
<copy todir="dest">
    <dirset refid="exists.dirs" />
</copy>

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