1

I am using the maven-replacer-plugin (https://code.google.com/p/maven-replacer-plugin/wiki/UsageGuide). I am using the use-case explained "Single file replacement using a tokenValueMap".

I am not able to get the tokens replaced properly in the source file that is having these tokens.

Requirement I need to generate an XML file with field values for the tokens, taken from a properties file.

The XML file, is in the format as below.

XML_DEV.txt

 <field>
     <name>HTTP/Server</name>
     <value>${Server}</value>
 </field>
 <field>
     <name>HTTP/Port</name>
     <value>${Port}</value>
 </field>

I have the values of these placeholder variables (Server and Port) defined in separate properties files for each environment (DEV, QA, PROD).

Application_DEV.properties

Server=DEV_Application_Server1
Port=8081

Application_QA.properties

Server=QA_Application_Server11
Port=8082

I am using ${..} to identify the tokens in the Source XML file (XML_DEV.txt). I am using the tokenValueMap to identify the list of tokens and the values that needs to be replaced for these tokens.

What is happenning so far..

I am able to get the values replaced, but the ${} braced is not getting removed in the output file generated. Example for QA replacement. Input (sample from file XML_DEV.txt)

 <field>
     <name>HTTP/Server</name>    
     <value>${Server}</value>
 </field>

is being changed to

Output (sample from file XML_DEV_mod.txt)

 <field>
     <name>HTTP/Server</name>
     <value>${QA_Application_Server11}</value>
 </field>

All tokens are getting changed, but the '${ }' is still present in the output file as above. My POM file used is as below. Please let me know if I am missing something, to force Maven to remove the ${ }.

My Current POM file

<build>
    <plugins>
        <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.2</version>
            <executions>                
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>                    
                </execution>
            </executions>
            <configuration>
                <file>${inputFile}</file>
                <tokenValueMap>DEV_properties.txt</tokenValueMap>
                <outputFile>${outFileName}</outputFile>
            </configuration>
        </plugin>
    </plugins>
</build>

DEV_properties.txt (token value map)

Server=DEV_Application_Server1
Port=8081
inputFile=XML_DEV.txt
outFileName=XML_DEV_mod.txt

Appreciate your help on this.

Thanks in Advance

-Raghu

PS: I had an earlier post (query) regarding this Issues, where I was suggested to use Filtering to solve this Requirement. I am still working on the filter option (though I have not been successful so far), when I found this replacer-plugin to get the tokens replaced.

Maven - Solution to replace variables in a XML file after fetching their values from a properties file

Community
  • 1
  • 1
Raghu
  • 33
  • 1
  • 7

1 Answers1

0

An update, I was able to solve the Issue by using <delimiters>, and when I used % as the token, as below.

<build>
    <plugins>
    <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>1.5.2</version>
        <executions>                
        <execution>
            <phase>prepare-package</phase>
            <goals>
            <goal>replace</goal>
            </goals>                    
        </execution>
        </executions>
        <configuration>
        <delimiters>
          <delimiter>%</delimiter> 
        </delimiters>
        <file>${inputFile}</file>
        <tokenValueMap>DEV_properties.txt</tokenValueMap>
        <outputFile>${outFileName}</outputFile>
        </configuration>
    </plugin>
    </plugins>
</build>

This could change the input file containing tokens as below

 <field>
     <name>HTTP/Server</name>    
     <value>%Server%</value>
 </field>

to

 <field>
     <name>HTTP/Server</name>
     <value>QA_Application_Server11</value>
 </field>

as required.

I would have loved to have ${Var} changed as mentioned in the problem. But this solves the requirement.

Thanks to the below post, Managing Google Maps API keys

Regards

-Raghu

chrki
  • 6,143
  • 6
  • 35
  • 55
Raghu
  • 33
  • 1
  • 7