2011-05-31 35 views
4

我想從標準文本文件中獲取文本並將其插入到由Apache Ant替換標記複製的XML中。這可能嗎?Apache Ant:是否可以插入/替換原始文本文件中的文本?

實例(這是我使用至今):

<macrodef name="generateUpdateFile"> 
    <sequential> 
     <echo message="Generating update file ..." level="info"/> 
     <copy file="update.xml" tofile="${path.pub}/update.xml" overwrite="true"> 
      <filterchain> 
       <replacetokens> 
        <token key="app_version" value="${app.version}"/> 
        <token key="app_updatenotes" value="${app.updatenotes}"/> 
       </replacetokens> 
      </filterchain> 
     </copy> 
    </sequential> 
</macrodef> 

的$ {} app.updatenotes目前是在build.properties文件中定義的字符串。但是,我想用一個簡單的文本文件編寫更新註釋,並從那裏獲取它們。

回答

6

apache ant loadfile任務將允許您讀取您的文本文件,並將其內容放入app.updatenotes屬性中。

您可以簡單地使用:

<loadresource property="app.updatenotes"> 
    <file file="notes.txt"/> 
</loadresource> 

然後,用你的filterchain,就像以前一樣。 loadresource有一些選項,例如控制文件的編碼,或者控制如果文件不存在或不可讀時如何反應。

+0

太棒了!感謝tonio提示! – BadmintonCat 2011-05-31 18:13:35

相關問題