I have some configurations that change based on the environment the project is being deployed to. I am thinking of adding the properties file tosrc/resources
that could be edited by DevOps while deploying the project. I'll need the pom.xml
file to read these properties. Is there a way to do that?
Asked
Active
Viewed 497 times
1

Dmitry Rakovets
- 557
- 1
- 6
- 15

Jasmine
- 135
- 3
- 16
-
_Usually_ the artifact produced by a Maven project should be environment agnostic and the code itself is able to read a properties file or environment variables somehow at startup. – Gaël J Aug 22 '21 at 18:01
-
2Does this answer your question? [How to read an external properties file in Maven](https://stackoverflow.com/questions/849389/how-to-read-an-external-properties-file-in-maven) – Gaël J Aug 22 '21 at 18:07
-
I agree...but in my case, I am trying to deploy the Azure Function App that'll require me to provide the information(resourcegroup, region, etc) in the pom file to deploy it to the azure portal. – Jasmine Aug 22 '21 at 18:11
1 Answers
0
You don't need property files for that. You can declare the properties in <profiles>
in the POM itself and activate these alternately. See Maven / Introduction to build profiles:
A profile can be activated in several ways:
- ...
Profiles specified in the POM can modify the following POM elements:
- ...
<properties>
[...] Note that too many files to configure is very confusing and very hard to maintain. Bottom line is that since this is build data, it should be in the POM. One of the goals in Maven 2 is to consolidate all the information needed to run a build into a single file, or file hierarchy which is the POM.

Gerold Broser
- 14,080
- 5
- 48
- 107