我想用Ant代替源文件中的标记:
some test ${foo} other text ...
标记包含在属性文件中,例如:
foo=1
实际上,如果源文件中的标记类似于'@@ foo @@'或'foo',但是我无法替换整个标记,这很容易:$ {foo}
几年前我已经成功了,但这次我失败了......
由于
答案 0 :(得分:4)
这有点类似于these。
从文件properties.txt
加载属性。
这里的缺点是输入文本中所有出现的${
都会在令牌替换之前转换为{
- 如果该字符串出现在文本的其他位置,这可能会破坏事情。如果这是一个问题,那么仍然有可能适应这种解决方案。
<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>