我想从标准文本文件中获取文本并将其插入到由 Apache Ant 使用替换标记复制的 XML 中。这可能吗?
示例(这是我到目前为止使用的):
<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 文件中定义的字符串。但我想在一个简单的文本文件中编写更新注释并从那里获取它们。
最佳答案
Apache Ant loadfile任务将允许读取您的文本文件,并将其内容放入 app.updatenotes
属性中。
您可以简单地使用:
<loadresource property="app.updatenotes">
<file file="notes.txt"/>
</loadresource>
然后,像以前一样使用您的filterchain
。
loadresource
有一些选项,例如控制文件的编码,或者控制文件不存在或不可读时如何 react 。
关于 Apache Ant : Is it possible to insert/replace with text from a raw text file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6190923/