java 如何在 ant 属性中放置换行符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7102793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 18:37:55  来源:igfitidea点击:

How to put a newline in ant property

javaant

提问by Yoni

This doesn't seem to work:

这似乎不起作用:

<property name="foo" value="\n bar \n"/>

I use the property value in the body of an e-mail message (which is sent as plain text):

我在电子邮件消息的正文中使用属性值(以纯文本形式发送):

<mail ...>
  <message>some text${foo}</message>

and I get literal "\n" in the e-mail output.

我在电子邮件输出中得到文字“\n”。

回答by martin clayton

These all work for me:

这些都对我有用:

<property name="foo" value="bar${line.separator}bazz"/>

<property name="foo">bar
bazz2</property>

<property name="foo" value="bar&#10;bazz"/>

回答by Paul

You want ${line.separator}. See this postfor an example. Also, the Ant echo taskmanual page has an example using ${line.separator}.

你要${line.separator}。有关示例,请参阅此帖子。此外,Ant echo 任务手册页有一个使用${line.separator}.

By using ${line.separator}you're simply using a Java system property. You can read up on the list of system properties here, and here is Ant's manual pageon Properties.

通过使用,${line.separator}您只是在使用 Java 系统属性。您可以在这里阅读系统属性列表,这里是 Ant 的属性手册页