21

I need to set a URL via a maven property (to be replaced per profile). The problem is that this URL contains some & and maven doesn't like this (if URL contains &_program):

"The reference to entity "_program" must end with the ';' delimiter." error occurs in pom on this line.

So how to escape this character or how to escape a hole line that might contain some "special" characters. (What other characters are forbidden in property-values?)

dermoritz
  • 12,519
  • 25
  • 97
  • 185

2 Answers2

53

I've not used maven but from the sounds of it, standard XML escaping would get the job done. In your case you can try using

& instead of &

What characters do I need to escape in XML documents?

Community
  • 1
  • 1
mikey
  • 5,090
  • 3
  • 24
  • 27
46

You can escape one character or a whole line that might contain some "special" characters by surrounding property value with <![CDATA[ property value ]]>. For example for some URL it would look like:

<properties>
    <some.url><![CDATA[http://stackoverflow.com?param_1=1&param_2=2]]></some.url>
</properties>
Tomasz Szymulewski
  • 2,003
  • 23
  • 23