1. 程式人生 > >1、Maven配置多環境開發(dev、beta、prod)

1、Maven配置多環境開發(dev、beta、prod)

我們在線上開發的時候不免要用到多個環境開發,一種的開發環境,一種是測試環境,還有就是生產環境,我們在開發的時候不可能直接用線上的環境進行修改,因為這樣會帶來很多無可預知的麻煩,所以我們要進行環境隔離~

<build> </build>裡面新增下面引數,設定Maven多環境的時候資源是通用的。

<resources>
      <resource>
        <directory>src/main/resources.${deploy.type}</directory>
        <excludes
>
<exclude>*.jsp</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources>

如:
image.png

</build></project>之間配置下面引數:

<profiles>
    <
profile
>
<id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <deploy.type>dev</deploy.type> </properties> </profile> <profile> <
id
>
beta</id> <properties> <deploy.type>beta</deploy.type> </properties> </profile> <profile> <id>prod</id> <properties> <deploy.type>prod</deploy.type> </properties> </profile> </profiles>

如:
image.png

上面的<deploy.type>對應著最首先新增jsp裡面的${deploy.type}

image.png


配置完成之後,我們點選IDEA的Maven Project就會發現有對應的引數新增進去了~
在配置多環境的時候我們給dev設定為true,所以也就預設選中為dev了~

  <activation>
        <activeByDefault>true</activeByDefault>
  </activation>

image.png