0

I need to edit an XML file with field values taken from a properties file.

The XML file, is in the format as below. ServiceConfig_Template.xml

 <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 would need to populate the ServiceConfig_Template.xml file that is having placeholders (${Server} and ${Port}) of the variables; their values being defined in the properties file (Application_DEV.properties), and then write the edited values into a different XML.

How can I use Maven to lookup the variable placeholders values available in the properties file and output the updated XML file(ServiceConfig_Template.xml) accordingly.

The output genetrated for DEV, should be as below.

 <field>
     <name>HTTP/Server</name>
     <value>DEV_Application_Server1</value>
 </field>
 <field>
     <name>HTTP/Port</name>
     <value>8081</value>
 </field>

There are 100s of variables like these in the "ServiceConfig_Template.xml". How can I use Maven replacer plugin, to do the lookup of the variable field values defined with the ${..} quotes.

The example shown in the site (http://code.google.com/p/maven-replacer-plugin/), i think replaces only one or few fields. I would request help on arriving at a generic solution for all the variable fields in the "ServiceConfig_Template.xml".

Appreciate help on this.

Thanks -Raghu

Raghu
  • 33
  • 1
  • 7
  • I would suggest to take a deep look at filtering by using usual filtering mechanism by maven see http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html for details. – khmarbaise Jun 23 '15 at 18:32
  • Thanks khmarbaise and 'Eugene Kuleshov'. I did more reasearch on using filtering and profiles. Looks very promising. Will post an update in a day or two. – Raghu Jun 24 '15 at 16:54

1 Answers1

1

You can use properties-maven-plugin to load properties from a file and specify which properties plugin configuration is used by using several profiles in the pom.xml.

Eugene Kuleshov
  • 31,461
  • 5
  • 66
  • 67