I’m using Maven 3.2.3. I have this plugin in my pom.xml file …
<!-- creates a test database script from the properties file -->
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>src/test/resources/META-INF/db-test-data.sql.templ</file>
<outputFile>target/test-classes/db-test-data.sql</outputFile>
<tokenValueMap>src/test/resources/test.properties</tokenValueMap>
</configuration>
</plugin>
I notice that when my “test.properties” file contains a property like so
test.sample.school2.name=Middle $ample Elementary #2
I get the below error when the plugin executes …
[ERROR] Failed to execute goal com.google.code.maven-replacer-plugin:replacer:1.5.3:replace (default) on project core: Illegal group reference -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
The problem is with the “$” in the replaced value. If I remove it, everything is fine. However, sometimes the replaced value will have a “$”. Is there a way to configure the plugin to accept the “$”, or barring that, is there an equivalent plugin I can use that will achieve the same thing as above?
You should escape the
$token (and other such regex symbols):Just so you know, the
$character is used to denote the matching groups in during the replacement in regex (hence the error message).This has nothing to do with the escaping required on the keys in a property file when loading of course, but this plugin probably does a
replaceAllfor regex support.Quoting its javadoc,
but apparently, the
replacerplugin's code doesn't use thequoteReplacementto escape an arbitrary replacement string (in this case, it's the string:"Middle $ample Elementary #2"), so you must escape it yourself.If you don't intend to use regex matching/replacements at all, you could set the
regexflag tofalsein the plugin configuration: