Ant 文件集扩展不起作用
我从 ant 构建文件中得到了非常令人困惑的反应,我想知道是否我不够聪明,或者这实际上可能是一个错误。
我在我的项目中全局设置了以下属性:
<property name="lib.dir" location="lib"/>
然后我将尝试通过文件集(多个资源)将此目录中的一些文件添加到 jar 文件中:
<fileset dir="${basedir}" includes="lib/*filename*"/>
应该有(并且存在)3 个不同的库,就是这样匹配的。但是,如果我尝试使用以下内容,它不起作用,并且不包含任何文件:
<fileset dir="${basedir}" includes="${lib.dir}/*filename*"/>
请注意,唯一的区别在于全局属性的使用。现在有一个简单的问题:为什么第一个版本可以像宣传的那样工作,但第二个版本却不能?
I get a very confusing reaction from my ant build-file and I'm wondering whether I'm just not clever enough or this might actually be a bug.
I've got the following property set globally in my project:
<property name="lib.dir" location="lib"/>
Then I'll try to add some files out of this directory into a jar file via fileset (more than one resource):
<fileset dir="${basedir}" includes="lib/*filename*"/>
There should be (and exist) 3 different libraries, which are matched that way. However, if I try to use the following, it doesn't work and no files are included:
<fileset dir="${basedir}" includes="${lib.dir}/*filename*"/>
Note that the only differences lies in the usage of the global property. Now the simple question: why does the first version work as advertised, but the second doesn't?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请在使用“fileset”表达式的任务之前或之后检查“lib.dir”的实际值。只是为了确保在全局设置后它没有被意外更改。
任务可以提供帮助。也许我找到了解决方案。
location
属性的描述是:只需使用
value
属性而不是location
即可。这是一个测试脚本来显示差异:我的系统上的输出如下:
Please check the actual value of "lib.dir" just before and maybe after the task that uses the "fileset" expression. Just to make sure, that it hasn't been changed accidently after you've set it globally. The
<echo/>
task can help.Maybe I got the solution. The description of the
location
attribute is:Simply use the
value
attribute instead oflocation
. Here's a test script to show the difference:The output on my system is as follows:
我已经找到了答案的线索,但还没有找到全部。
我使用 ant -debug 运行了两个版本的文件集,结果如下。
在工作的、不使用属性的版本中,我得到以下输出:
而在应该工作但不工作的版本中,我得到:
fileset: Setup Scanner in dir [pathToDir] with patternSet{ include: [ [pathToDir]/lib/*filename*] excepts: [] }
如您所见,ant add 的是正则表达式中的 [pathToDir],因此搜索
显然不存在的路径。现在的问题是:我该如何修改我的版本才能使其正常工作?
I have found a clue to the answer, but not the whole thing yet.
I runned both versions of the fileset with ant -debug and here is what happens.
In the working, not-using-property version, I get the following output:
whereas in the should-be-working-but-doesn't version I get:
fileset: Setup scanner in dir [pathToDir] with patternSet{ includes: [ [pathToDir]/lib/*filename*] excludes: [] }
As you can see, ant add's the [pathToDir] in the regexp, thus searching for
which obviously doesn't exist. Problem now: how do I have to modify my version to have it working properly?
创建属性时(是在全局还是在目标中完成?),目录
lib
是否存在?如果不是,则location
属性不起作用 - 请改用value
属性,或者更好地在创建目录后定义该属性。When creating the property (is it done global or in a target?), does the directory
lib
exist? If not, thelocation
attribute does not work - use avalue
attribute instead or better define the property after creating the directory.如上所述,问题是 ${lib.dir} 也包含整个路径,因此搜索 [pathToDir]/[pathToDir]/lib/filename。
为了剪掉 ${lib.dir} 属性中不需要的 [pathToDir],我现在使用了该任务。我现在得到了以下内容,但恕我直言,看起来不太好看的解决方案:
PS:再看一遍,我发现 Andreas_D 昨天也找到了正确的理由和一个很好的建议,我一定忽略了:-/
As indicated above, the problem was that ${lib.dir} too contained the whole path, thus searching for [pathToDir]/[pathToDir]/lib/filename.
To clip away the unwanted [pathToDir] in the ${lib.dir} property, I now used the task. I got now the following, but imho not so nice looking solution:
P.S.: On a second look, I found that Andreas_D also found the right reason and a good suggestion yesterday, which I must have overlooked :-/