Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store Apache Ant property value in file

Tags:

ant

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.

like image 694
wheleph Avatar asked Nov 04 '08 14:11

wheleph


People also ask

What is property in build xml?

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.

How do I run an Ant file in xml?

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.

What is Antcall in build xml?

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.


2 Answers

You can use the echo task.

<echo file="${fileName}" message="${xmlProperty}"/>

The echoxml task might be of interest to you as well.

like image 54
sblundy Avatar answered Sep 23 '22 17:09

sblundy


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.

like image 28
Jarekczek Avatar answered Sep 23 '22 17:09

Jarekczek