在Ant Build文件中使用正則表達式替換文件內容

這須要在build文件中使用<replaceregexp>標籤, 這個標籤的使用大概是這個樣子的:
1 <replaceregexp file="${src}/build.properties"
2                match="OldProperty=(.*)"
3                replace="NewProperty=\1"
4                byline="true"
5 />

 

 
注意,Ant默認是不認識這個標籤的,爲了使用這個標籤,須要在Build文件中加入預約義:
1 <taskdef resource="net/sf/antcontrib/antcontrib.properties">
2         <classpath>
3             <pathelement location="${ant.home}/exlib/ant-contrib-1.0b3.jar" />
4         </classpath>
5 </taskdef>

 


這裏須要使用ant-contrib-1.0b3.jar文件,請檢查你的ant安裝目錄下有沒有這個文件
 
另外須要注意的是,正則表達式寫在xml中的時候,自己也是須要轉義的,這個請參考xml的語法
相關文章
相關標籤/搜索