2014-09-04 83 views
1

在ant中,如何将文件的文件路径转换为相对路径?以下是我迄今为止仍然保持完整路径,文件从完整路径转换为相对路径

<path id="build.classpath"> 
<fileset dir="../../lib"> 
<include name="*.jar"/> 
</fileset> 
</path> 
<pathconvert property="mf.classpath" pathsep=" " refid="build.classpath"> 
<map from="${build.classpath}" to="lib/"/> 
</pathconvert> 

回答

3

上述问题的解决方案如下

<path id="build.classpath"> 
<fileset dir="../../lib"> 
    <include name="*.jar"/> 
</fileset> 
</path> 
<pathconvert property="mf.classpath" refid="build.classpath" pathsep=" "> 
<chainedmapper> 
<flattenmapper/> 
<globmapper from="*" to="../lib/*"/> 
</chainedmapper> 
</pathconvert> 

使用链映射器链中的不同映射起来,并压平该字符串只是文件名。然后遍历所有文件并将相对路径追加到前面。