开发者

Apache Ant: Is it possible to insert/replace with text from a raw text file?

I'd like to take text from a standard text file and insert it into an XML that is copied with replace tokens by Apache Ant. Is this possible?

Example (this is what I use so far):

<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>

The ${app.updatenotes} are currently a string that is defined in a build.properties file. But instead I'd like to write update notes in a simple text file and take them from there.


The apache ant loadfile task will allow to read your text file, and put its content into the app.updatenotes property.

You can simply use:

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

Then, use your filterchain, just as before. loadresource has some options, for instance to control the encoding of your file, or to control how to react if the file is not present, or not readable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜