2012-11-27 81 views
3

在我的構建文件我有一個Ant目標中,我有下面的代碼片段,如何使用ant replaceregex任務在Windows中用文件路徑替換一行?

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

我想替換的路徑「custom.dir」屬性中的「configuration.properties」文件,然而,一旦我執行我的目標,我得到修改,以

custom.dir = C爲 「custom.dir」 屬性條目:arenaplaygroundmytestapp /任務/定製

,而不是

custom.dir = C:\競技場\操場\ mytestapp /任務/定製

我應該做的正確書寫與適當的文件分隔符的 「configuration.properties」 文件的路徑。我在窗戶和螞蟻使用的是螞蟻1.8。

回答

4

當您試圖將WINDOW_STYLE_PATH寫入文件時,WINDOW_FILE_SEPARATOR被識別爲轉義序列字符。所以你可以在寫入文件之前改變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> 
+0

感謝Vishal,作爲魅力。 – jay