今天在编辑Ant脚本中,需要在打包的时候在配置文件末尾加一句配置。
一开始直接写
<echo message="Last-Modified=${NOW}" file="${dist.dir.classes}/config.properties" append="true" />
运行后发觉有问题,输出的语句与配置文件最后一行连在了一行中,而没有另起一行输出。
然后我天真的以为前面加上“\n”就可以解决。事实证明我错了。
然后再google上搜到了解决方法:
原文如下:
You could use the built in property ${line.separator} (this comes from the set of java system properties):
<echo message="First line${line.separator}Second line"/>
原来Ant脚本中有专门的变量来处理换行符。
修改我的脚本
<echo message="${line.separator}Last-Modified=${NOW}" file="${dist.dir.classes}/config.properties" append="true" />
解决问题
网友评论