我在 Eclipse 中有一个 Ant 任务来从文件获取版本:
<loadfile property="version" srcfile="version.txt">
<filterchain>
<linecontainsregexp>
<regexp pattern="^#define version .(\d{1,10})\.(\d{1,10})\.(\d{1,10})\.(\d{1,10})."/>
</linecontainsregexp>
<replaceregex
pattern="^#define version .(\d{1,10})\.(\d{1,10})\.(\d{1,10})\.(\d{1,10})..*$"
replace="\1.\2.\3.\4" />
</filterchain>
</loadfile>
<echo message="Version ${version}"/>
版本显示时不带换行符。在代码中,我想将该属性与移动任务一起使用:
<move file="${dir}\file.exe"
tofile="${outputdir}\output-${version}-xxx.exe"
overwrite="true"
force="true" />
但是失败并显示消息
BUILD FAILED build.xml:26: Failed to copy path\file.exe to path\output_directory\output-1.0.0.0
-xxx.exe due to output-1.0.0.0
-xxx.exe (Název souboru či adresáře nebo jmenovka svazku je nesprávná)
(最后一行表示文件名无效,显然中间包含换行符)。
我哪里出错了?是特性本身吗?甚至添加行
<replaceregex pattern=" " replace="" flags="s"/>
或从属性中删除换行符的其他尝试没有改变任何内容。
最佳答案
您需要strip line breaks ,例如:
<filterchain>
<linecontainsregexp ... />
<replaceregex ... />
<striplinebreaks />
</filterchain>
如果您修改您的<echo>
至:
<echo message="Version -${version}-"/>
您会清楚地看到效果。
关于eclipse - Ant 移动将换行符放在属性末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16305671/