I have a default properties file, and some deployment specific properties files that override certain settings from the default, based on deployment environment. I would like my Ant build script to merge the two properties files (overwriting default values with deployment specific values), and then output the resulting properties to a new file.
I tried doing it like so but I was unsuccessful:
<target depends="init" name="configure-target-environment">
<filterset id="application-properties-filterset">
<filtersfile file="${build.config.path}/${target.environment}/application.properties" />
</filterset>
<copy todir="${web-inf.path}/conf" file="${build.config.path}/application.properties" overwrite="true" failonerror="true" >
<filterset refid="application-properties-filterset" />
</copy>
</target>
I did it like this:
I personally use this:
I figured this one out. There needs to be an extra properties file created, with each key/value in the following format: mail.server.host=@mail.server.host@ etc...
Then specify this "template" file to the "file" attribute of the task. Also in the filterset, specify multiple with the least important one listed first.
So it would look like this:
Perhaps you should look at the concat task of ant for this.
The other answers are okay, but I needed one without these limitations:
In the end I had to resort to javascript in a filter, but my solution brings in default properties if and only if they are not defined in the main properties file. It works by loading the main properties with an obscure prefix, then copying it to the destination, then concat'ing the default properties while filtering out any default properties that were loaded in the first step.
You can use this verbatim but will probably want to take out the log statements or change them to debug level, once you're convinced