Search code examples
javaxmlmavenxsdmaven-resources-plugin

How to stop backslashes being escaped when filtering with maven-resources-plugin?


I'd like to use the Maven Resources Plugin to set the XML schema location within an XML resource file:

<root xsi:noNamespaceSchemaLocation="${env.myxsdpath}" ...>

This works except for one thing - the substituted path has double backslashes instead of a single blackslash, e.g:

<root xsi:noNamespaceSchemaLocation="C:\\mypath\\myschema.xsd" ...>

So two questions:

  1. Is this a valid format for specifying the XSD file?
  2. Is there a way to tell Maven to use a single backslash instead of double backslashes?

The environment variable myxsdpath is C:\mypath\myschema.xsd. The maven-resources-plugin doesn't have any special configuration other than specifying the files that are to be included with filtering turned on.


Solution

  • This behaviour is controlled by the escapeWindowsPaths attribute of the maven-resources-plugin, introduced in version 2.4. It defaults to true meaning that, by default, all back-slashes will be escaped, turning single \ into double \\.

    Whether to escape backslashes and colons in windows-style paths.

    Sample configuration to disable this:

    <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <version>2.7</version>
      <configuration>
        <escapeWindowsPaths>false</escapeWindowsPaths>
      </configuration>
    </plugin>