Here is a property file:
test.url=https:\\url:port
test.path=/home/folder
test.location=Location
test.version=1
And the following ant task:
I can pass temporary value for one run of a task:
ant -Dtest.path=new_path test_props
How can I overwrite test.path value with one I pass using -D key? In order, after the same launch, the value of test.path would change to one I pass above?
The following variants don’t work:
<entry key="test.path" value="${test.path}"/>
or
<propertycopy name="test.path" from="${test_path}"/>
If you want to permanently change a file, you could use the task.
I’d do the following:
Create a sample property file, like default.properties.sample.
Create a target that receives the given -D property, then, if it’s been informed, does a replace on file default.properties.sample saving it into a default.properties file. The default.properties.sample would have these lines:
The action would replace the @test_path@ token with the real value of the property, as informed in the -D parameter, then save the resulting file as default.properties. Something like:
Some adjustments need to be made, like: only replace the property if the -D parameter is informed, or else the file would be replaced every time.
Paths and like should also be adjusted to your needs.
I’ve tested the following scenario and it worked for me:
I’ve created two files: a build.xml and a default.properties.sample. Their contents is as follows:
build.xml
default.properties.sample:
And they run to the following tests:
Default run:
Error control:
Replace of property:
Property file after replacement:
And in a subsequent runs the new value of the test.property is present:
I think that is what you’re looking for.