如何使用 Ant 在文件末尾附加一些文本? [英] How do I append some text at the end of a file using Ant?

查看:26
本文介绍了如何使用 Ant 在文件末尾附加一些文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目的配置文件之一中,我需要附加一些文本.我正在寻找一些使用 Ant 执行此操作的选项.

In one of the configuration files for my project I need to append some text. I am looking for some options to do this using Ant.

我找到了一个选项 - 查找某些内容并将该文本替换为新文本和旧值.但这似乎并不乐观,好像将来有人更改原始文件一样构建会失败.

I have found one option - to find something and replace that text with the new text, and the old values. But it does not seems to be promising, as if in future someone changes the original file the build will fail.

因此,我希望我的脚本在文件末尾添加文本.

So, I would like my script to add the text at the end of the file.

对于这样的要求,我有哪些选择?

What options do I have for such a requirement?

推荐答案

使用 echo 任务:

<echo file="file.txt" append="true">Hello World</echo>

如果你有 HTML(或其他任意的 XML),你应该用 CDATA 转义它:

If you have HTML (or other arbitrary XML) you should escape it with CDATA:

<echo file="file.txt" append="true">
<![CDATA[
  <h1>Hello World</h1>
]]>
</echo>

这篇关于如何使用 Ant 在文件末尾附加一些文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆