I have configuration.properties in configs/Configuration.properties where I have url path = http://finacial/dev3/api http:// financial/{env}/api I want to load the environment value from the pom.xml to replace dev 3 according to the environment property set in pom.xml.
Asked
Active
Viewed 327 times
1 Answers
0
You could use the filter option of the maven resources plugin, it does exactly that.
Variables can be included in your resources. These variables, denoted by the ${...} delimiters, can come from the system properties, your project properties, from your filter resources and from the command line.
E.g. if you have a property url
in your pom
<properties>
<url>abc</ulr>
</properties>
and your .properties file contains a value ${url}
and you include the file in the resource section of the pom, then ${url}
will be replaced in the output file in the build target location by abc
upon issuing mvn resources:resources
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>

Curiosa Globunznik
- 3,129
- 1
- 16
- 24
-
I have my urlPath specified in the configs/configuration.properties where it contains environment. http://financial/dev3/api, I have changed it to http://financial/{env}/api. And in pom.xml I have
dev3. I want this env value to be updated in my urlPath -
So it is not at all in the project directory and not covered in the build? If it is you should be fine by adding it the way `src/main/resources` was added in the example. – Curiosa Globunznik Nov 05 '19 at 22:13
-
No. It is not. I need it to run my BDD script. I edit the environment to refer to the particular env for testing, When I run my BDD script I want other config files also to use the env specified in pom.xml – Priyankaa Nov 05 '19 at 22:18
-
It is similar to this https://stackoverflow.com/questions/48259808/how-to-update-a-property-file-using-maven-or-pom-xml but I have my properties file like urlPath=http://financial/dev/api – Priyankaa Nov 05 '19 at 22:19
-
Can't really comment on that. I found this [replacer plugin](https://stackoverflow.com/questions/15157779/maven-replacer-plugin-and-multiple-files), otherwise you can run any ant-command with the [antrun](https://maven.apache.org/plugins/maven-antrun-plugin/) plugin, they have all kind of [replace stuff](https://ant.apache.org/manual/Tasks/replaceregexp.html). – Curiosa Globunznik Nov 05 '19 at 22:23