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?
Another option would be to use a filterchain.
For example, the following will append file
input2.txt
toinput1.txt
and write the result tooutput.txt
. The line separators for the current operating system (from the java properties available in ant) are used in the output file. Before using this you would have to createoutput2.txt
on the fly I guess.Use the echo task:
EDIT: If you have HTML (or other arbitrary XML) you should escape it with
CDATA
:I found the other answers useful, but not giving the flexibility I needed. Below is an example of writing echos to temp file that can be used as a header and footer, then using concatenation to wrap an xml document.
The concat task would look to do it as well. See http://ant.apache.org/manual/Tasks/concat.html for examples, but the pertinent one is: