26

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.

Yoni
  • 10,171
  • 9
  • 55
  • 72

2 Answers2

37

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"/>
martin clayton
  • 76,436
  • 32
  • 213
  • 198
  • Not directly related but the ReplaceRegExp task only allowed me to use the XML characters to replace. ${line.separator} only worked when put in the beginning. – leeman24 Sep 05 '18 at 21:18
20

You want ${line.separator}. See this post for an example. Also, the Ant echo task manual page has an example using ${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 page on Properties.

Paul
  • 19,704
  • 14
  • 78
  • 96
  • Note that `${line.separator}` is platform specific, therefore the build become platform dependent. – Robert Hume Sep 02 '17 at 18:22
  • 1
    @RobertHume No it wouldn't. OP is sending an e-mail using Ant's [mail task](https://ant.apache.org/manual/Tasks/mail.html) and is using the newline in the e-mail message. Referencing `${line.separator}` will not change the output of the build. – Paul Sep 02 '17 at 19:36
  • Right, in this case there's no risk. Thanks! – Robert Hume Sep 02 '17 at 19:39
  • I'm developing in windows and my build outputs generates a "run.sh" for linux users. By using this ${line.separator} the build always outputs \r\n as line separators, making the .sh script unusable. – Gustavo Jul 04 '19 at 15:02
  • 2
    @Gustavo, `${line.separator}` is a system property. You tried to use the system property from one system to create something for another system. Since you know your target system you can hardcode the desired separator...there was no need for you to use `${line.separator}`. – Paul Jul 05 '19 at 14:23
  • @Paul Sorry, I didn't notice the " ". This is exactly what I was looking for. – Gustavo Jul 05 '19 at 14:36