Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i setup my maven pom for different environment builds?

Tags:

maven

maven-3

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?

like image 836
Jane Wayne Avatar asked Nov 11 '22 11:11

Jane Wayne


1 Answers

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

like image 97
Amin Abu-Taleb Avatar answered Nov 15 '22 07:11

Amin Abu-Taleb