1、Maven配置多环境开发(dev、beta、prod)

版权声明: https://blog.csdn.net/czjlghndcy/article/details/83385766

我们在线上开发的时候不免要用到多个环境开发,一种的开发环境,一种是测试环境,还有就是生产环境,我们在开发的时候不可能直接用线上的环境进行修改,因为这样会带来很多无可预知的麻烦,所以我们要进行环境隔离~

<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

猜你喜欢

转载自blog.csdn.net/czjlghndcy/article/details/83385766