使用相对文件名进行路径转换
在文件夹 src 中,我有一组包含 java 源代码的子文件夹:
/a/A.java
/a/b/B.java
/a/b/c/C.java
我需要一个具有以下值的属性:
src/a/A.java,src/a/b/B.java,src/a/b/c/C.java
I尝试了以下操作:
<pathconvert property="list-of-files">
<globmapper from="*" to="src/*"/>
<fileset dir=${src-folder}/>
</pathconvert>
但我最终在我的财产上得到以下值:
src/full/path/to/folder_a/a/A.java,src/full/path/to/folder_a/a/b/B.java,src/full/path/to/folder_a/a/b/c/C.java
我怎样才能实现我想要的?任何意见表示赞赏!
In folder, src, I have a set of subfolders with java source code:
/a/A.java
/a/b/B.java
/a/b/c/C.java
I need a property with the following value:
src/a/A.java,src/a/b/B.java,src/a/b/c/C.java
I tried the following:
<pathconvert property="list-of-files">
<globmapper from="*" to="src/*"/>
<fileset dir=${src-folder}/>
</pathconvert>
but I end up with the following value on my property:
src/full/path/to/folder_a/a/A.java,src/full/path/to/folder_a/a/b/B.java,src/full/path/to/folder_a/a/b/c/C.java
How can I accomplish what I want? Any input is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 pathconvert 的
map
参数来实现此目的。首先通过将其路径附加到
basedir
属性的值来获取 src 目录的完整路径。然后将其用作地图的from
属性。You can use the
map
parameter of pathconvert for this.First get the full path to your src dir by appending its path to the value of the
basedir
property. Then use that as thefrom
attribute of your map.以防万一,如果有人需要获取资源的相对文件路径并将它们相应地映射到 URL 路径,因此它在 Windows 和 *nix 上都适用,解决方案是:
Just in case if someone needs to get relative file paths of resources and map them to URL paths accordingly, so it works both on Windows and *nix the solution is:
尝试以下之一:(
此处 N - 要删除的目录数(必须为正数))
或以下:
处理文件列表之后
在您的代码片段通过希望此帮助=)
Try either this one:
(here N - Number of directories to strip (must be a positive number))
or this:
after piece of your code treat list-of-files through the
Hope this help =)