使用带有 ant 的 replaceregexp 将新行从 linux 转换为 windows

Convert new lines from linux to windows using replaceregexp with ant

我想在 ant 脚本上使用 replaceregexp 将所有源代码转换为 windows 行,但对于更多组合,我尝试失败了。

我尝试了下一个代码,但它打印的是文字 "rl":

<replaceregexp match="\n" replace="\r\n" flags="g" byline="false" >
    <fileset dir="${src}">
        <include name="**/*.java" />
    </fileset>
</replaceregexp>

我不能使用 ${line.separator},因为我正在从 linux 执行 ant 脚本,所以它被评估为 \n

可以做到吗?怎么样?

您可以使用专门用于此目的的 Ant <fixcrlf> 任务。类似于:

<fixcrlf eol="crlf" srcdir="${src}" includes="**/*.java" />

还有一个优点是无需添加多个 \r 个字符即可安全重复。

要使用 replaceregexp 任务自行插入 CRLF,请使用 XML 个实体:

... replace="&#13;&#10;" ...