Ant replace token from properties file

I would like to replace the tokens in the source files with Ant:

some test ${foo} other text ... 

Tokens are contained in the properties file, for example:

 foo=1 

Actually, this is easy if the tokens in the source files were similar to "@@ foo @@" or "foo", but I cannot replace the whole token: $ {foo}

I succeeded many years ago, but this time I failed ...

thanks

+7
ant
source share
1 answer

It is somewhat similar to these .

Properties are loaded from the properties.txt file. The weakness here is that all occurrences of ${ in your source code are converted to { before replacing the token - which can really upset things if this line appears elsewhere in the text. If this is a problem, it is still possible to adapt this solution.

 <copy file="input.txt" tofile="output.txt"> <filterchain> <replaceregex pattern="\$\{" replace="{" /> <filterreader classname="org.apache.tools.ant.filters.ReplaceTokens"> <param type="propertiesfile" value="properties.txt"/> <param type="tokenchar" name="begintoken" value="{"/> <param type="tokenchar" name="endtoken" value="}"/> </filterreader> </filterchain> </copy> 
+4
source share

All Articles