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

I want to take text from a standard text file and paste it into XML, which is copied with the replacement of Apache Ant tokens. Is it 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> 

$ {app.updatenotes} is currently the line that is defined in the build.properties file. But instead, I would like to write update notes in a simple text file and take them from there.

+4
source share
1 answer

The apache ant loadfile task allows you to read your text file and put its contents in the app.updatenotes property.

You can simply use:

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

Then use the filterchain as before. loadresource has some options, for example, to control the encoding of your file or to control how to respond if the file is missing or cannot be read.

+6
source

All Articles