如何在windows中使用ant replaceregex任务替换具有文件路径的行?

如何在windows中使用ant replaceregex任务替换具有文件路径的行?,ant,build-automation,build-script,Ant,Build Automation,Build Script,在我的构建文件中,我有一个ant目标,其中有以下代码段 <replaceregexp replace="custom.dir=${basedir}/tasks/custom" byline="true" file="${basedir}/MyApp/configuration.properties"> <regexp pattern="custom.dir=(.*)"/> </replaceregexp> 我想用“configurat

在我的构建文件中,我有一个ant目标,其中有以下代码段

 <replaceregexp replace="custom.dir=${basedir}/tasks/custom" byline="true" file="${basedir}/MyApp/configuration.properties">
        <regexp pattern="custom.dir=(.*)"/>
 </replaceregexp>

我想用“configuration.properties”文件中的路径替换“custom.dir”属性,但是一旦我执行了我的目标,我就会将“custom.dir”属性的条目修改为

custom.dir=c:arenaplygroundmytestapp/tasks/custom

而不是

custom.dir=c:\arena\playerly\mytestapp/tasks/custom


我应该如何使用适当的文件分隔符将路径正确写入“configuration.properties”文件。我在windows上,使用的ant是ant 1.8

当您试图将窗口样式的路径写入文件时,窗口文件分隔符被识别为转义序列字符。因此,您可以在将路径写入文件之前以unix样式更改路径。Pathconvert将帮助您转换路径

<pathconvert property="new" dirsep="/">
    <path location="${basedir}"/>
</pathconvert>
    <echo message="${new}"/>
 <replaceregexp replace="custom.dir=${new}/tasks/custom" byline="true" file="${basedir}/configuration.properties">
        <regexp pattern="custom.dir=(.*)"/>
 </replaceregexp>