2011-05-31 82 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

相关问题