Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant 使用相对文件名进行路径转换_Ant_Mapper - Fatal编程技术网

Ant 使用相对文件名进行路径转换

Ant 使用相对文件名进行路径转换,ant,mapper,Ant,Mapper,在文件夹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 我尝试了以下方法: <pathconvert property="list-of-files"> <globmapper from="*" to="src/*"/> <fileset dir=${src-fol

在文件夹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
我尝试了以下方法:

<pathconvert property="list-of-files">
  <globmapper from="*" to="src/*"/>
  <fileset dir=${src-folder}/>
</pathconvert>
我怎样才能实现我想要的?欢迎您的任何意见

试试这个:

<pathconvert property="list-of-files">
  <globmapper from="*" to="src/*"/>
  <cutdirsmapper dirs="N"/>
  <fileset dir=${src-folder}/>
</pathconvert>

(此处N-要剥离的目录数(必须为正数))

或者这个: 在一段代码之后,通过

<mapper type="flatten"/>
<flattenmapper/>


希望此帮助=)

您可以为此使用的
map
参数

首先,通过将src dir的路径附加到
basedir
属性的值,获得src dir的完整路径。然后将其用作地图的
from
属性

<property name="src.dir" value="${basedir}${file.separator}${src-folder}"/>
<pathconvert property="list-of-files">
  <map from="${src.dir}" to="src"/>
  <fileset dir="${src-folder}"/>
</pathconvert>

如果有人需要获取资源的相对文件路径并相应地将它们映射到URL路径,那么它可以在Windows和*nix上工作。解决方案是:

<pathconvert dirsep="/" pathsep=";" property="css.files.list">
    <map from="${basedir}/" to="" /><!-- This is the trick. Remove slash to make path absolute. -->
    <fileset dir="." includes="${src.dir}/**/*.css" />
</pathconvert>


不幸的是,这些都不起作用。我不能使用第一种选择,因为在我的构建中,数字“N”不是常量。第二种选择是剥离所有文件夹,只留下一个Java文件列表。因此,我最终得到的结果是:A.java、B.java、C.java,这不是我想要的。您还可以通过位置而不是值获得绝对路径:
<pathconvert dirsep="/" pathsep=";" property="css.files.list">
    <map from="${basedir}/" to="" /><!-- This is the trick. Remove slash to make path absolute. -->
    <fileset dir="." includes="${src.dir}/**/*.css" />
</pathconvert>