如何为不同的环境构建设置Maven Pom? [英] how do i setup my maven pom for different environment builds?

查看:418
本文介绍了如何为不同的环境构建设置Maven Pom?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3种环境:

  1. 本地(dev)
  2. 登台
  3. 生产

每个环境使用不同的属性文件(例如,指定jdbc属性).目前,我的maven项目正在构建一个war文件.有人可以给我一些有关如何修改pom.xml文件的指导,以便我可以指定不同的版本吗?

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?

例如,如果我需要为舞台构建war文件,那么我需要对pom.xml文件做些什么才能使之发生,以便使用登台属性文件(包含在war中)?

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)?

让我更加清楚自己的构建.我正在使用Spring MVC,因此我可以切换存在的环境(例如属性文件).可以通过如下方式在web.xml中设置上下文参数来实现此目的.

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>

因此,基本上,如果我使用Maven概要文件,该如何交换该参数值?

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

推荐答案

您必须在pom.xml中定义不同的环境配置文件

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>

或为其指定一个特定的ID/名称

or give it a specific id/name like this

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

并使用mvn groupId:artifactId:goal -Pprofile-1

您可以在此处

这篇关于如何为不同的环境构建设置Maven Pom?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆