Friday, June 17, 2016

How to define environment specific parameters and resolve them during build time using maven - WSO2 ESB endpoints

Lets say we have multiple environments named DEV, QA, PROD, you need to have different Carbon Application (C-App) projects to group the dynamic artifacts for different environments such as endpoints, WSDLs and policies.

To address this we can have property file along with artifacts to store environment specific parameters. Maven can build the artifacts based on the properties in the property file to create artifacts that are specific to the given environment.

Given below is an example of this. An endpoint value should be different from one environment to another. We can follow the below approach to achieve this.

Define the endpoint EP1 as below, having a token for hostname which could be replaced later.
    <address trace="disable" uri="http://@replace_token/path"/>

Add the maven antrun plugin to replace the token using a maven property as below in pom file.
            <replace token= "@replace_token" value="${hostName}" dir="${basedir}/target/capp/artifacts/endpoint/EP1/">                                 
              <include name="**/*.xml"/>

Now build the project providing the maven property hostName as below,
mvn clean install -DhostName=
Instead of giving the hostname manually as above, now we can configure jenkins or any other build server to pick up the hostname from a config file and feed it as a system property to the build process.

Once we completed environment specific builds we will have 2 car files for each environment and they have same endpoints but actually they are pointed to different URLs as follows.

|___ End Point Project
        |__ backendEP.xml     //points to dev backend,
        |__ backendEP.xml     //points to qa backend,


  1. Nice to see your frequent posts, machan. Just came here to say hi. Hope all is well. :)


  2. Yes machan. You are one of the person who truly inspire me to blog :-) Still remember old good days.
    Everything is good. Hope you also doing good.