Ant replace token from properties file

前端 未结 1 1716
暖寄归人
暖寄归人 2021-01-12 07:55

i would like to replace tokens in source files with Ant:

some test ${foo} other text ...

Tokens are contained in a properties file eg.:

相关标签:
1条回答
  • 2021-01-12 08:32

    This is somewhat similar to these.

    Properties are loaded from the file properties.txt. The weakness here is that all occurrences of ${ in your input text are converted to { before the token substitution - which may well break things if that string appears elsewhere in the text. If that is a problem, it still aught to be 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>
    
    0 讨论(0)
提交回复
热议问题