Ant replace token from properties file

孤人 提交于 2019-12-30 08:32:21

问题


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

some test ${foo} other text ...

Tokens are contained in a properties file eg.:

foo=1

Actually this is easy if tokens in source files were like '@@foo@@' or 'foo' but i'm not able to replace whole token : ${foo}

I've succeed years ago but this time i've failed ...

Thanks


回答1:


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>


来源:https://stackoverflow.com/questions/3680362/ant-replace-token-from-properties-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!