I need to modify a (xml-)file from Apache Ant. "loadfile" task allows to load the file's content in a property. But how to store the property's value back to a file after its (property) modification?
Of course I could write custom task to perform this operation but I would like to know if there's some existing implementation.
Properties are key-value pairs where each value is associated to a key. The property is used to set value which can be accessed anywhere in the buildfile. Once a property is set, it cannot be changed. Apache Ant provides <property> tag which can be used to set property.
To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.
Description. Call another target within the same buildfile optionally specifying some properties (params in this context). This task must not be used outside of a target . By default, all of the properties of the current project will be available in the new project.
You can use the echo task.
<echo file="${fileName}" message="${xmlProperty}"/>
The echoxml task might be of interest to you as well.
Use propertyfile task. An example taken from ant manual:
<propertyfile file="my.properties">
<entry key="abc" value="${abc}"/>
</propertyfile>
This may be better than echo
as it updates the properties file with a given value, while echo
appends to or overwrites the whole file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With