Apache Ant:是否可以插入/替换原始文本文件中的文本?

Bad*_*Cat 4 apache ant replace insert

我想从标准文本文件中获取文本并将其插入到由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>
Run Code Online (Sandbox Code Playgroud)

$ {app.updatenotes}当前是在build.properties文件中定义的字符串.但我想在一个简单的文本文件中编写更新说明并从那里获取它们.

ton*_*nio 6

apache ant loadfile任务将允许读取您的文本文件,并将其内容放入app.updatenotes属性中.

你可以简单地使用:

<loadresource property="app.updatenotes">
   <file file="notes.txt"/>
</loadresource>
Run Code Online (Sandbox Code Playgroud)

然后,filterchain像以前一样使用你的. loadresource有一些选项,例如控制文件的编码,或控制文件不存在或不可读时如何反应.