Question

I have 3 environments:

  1. local (dev)
  2. staging
  3. production

each environment uses different properties files (e.g. to specify jdbc properties). currently, my maven project builds a war file. could someone please give me some guidance on how to modify the pom.xml file so that i can specify different builds?

for example, if i need to build the war file for stage, what do i need to do to the pom.xml file to make this happen so that the staging properties files is used (included in the war)?

let me be a little more clear with my build. i am using spring mvc, so i can toggle which environment (e.g. properties files) is present. the way this is accomplished is by setting the context parameter in web.xml as follows.

<context-param>
 <param-name>spring.profiles.active</param-name>
 <param-value>dev</param-value>
</context-param>

so, basically, if i use maven profiles, how do i swap out this parameter value?

Was it helpful?

Solution

You have to define different environment profiles in your pom.xml

<profiles>
  <profile>
    <activation>
      <property>
        <name>environment</name>
        <value>test</value>
      </property>
    </activation>
    ...
  </profile>
</profiles>

or give it a specific id/name like this

<profiles>
  <profile>
    <id>profile-1</id>
    ...
  </profile>
</profiles>

and run mvn using mvn groupId:artifactId:goal -Pprofile-1

You can find more information here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top