美文网首页
maven profile 打包多环境

maven profile 打包多环境

作者: 宇宙小神特别萌 | 来源:发表于2019-10-28 14:13 被阅读0次
maven profile 目录.png

说明:spring + maven 的项目
结构图

maven profile.png

前提:spring-mvc.xml 引入.properties文件

<!--资源文件导入 只能导入properties-->
<context:property-placeholder location="classpath:config/*.properties"/>

1、pom.xml 配置 profile

<profiles>
        <!--本地开发环境-->
        <profile>
            <id>local</id>
            <properties>
                <!--注:与结构木文件夹名称一致-->
                <profiles.active>local</profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <!--测试环境-->
        <profile>
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
            </properties>
        </profile>
        <!--生产环境-->
        <profile>
            <id>product</id>
            <properties>
                <profiles.active>product</profiles.active>
            </properties>
        </profile>
    </profiles>

2、pom.xml 配置 resource

    <build>
        <finalName>spring5x-web</finalName>
        <resources>
            <resource>
                <!--${profiles.active} 与上方配置的<profiles.active> 一致 -->
                <directory>src/main/profiles/${profiles.active}</directory>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>

3、IDEA 测试

idea:注意,要先执行清除-->编译或打包命令-->执行启动项目测试
不然会发现,项目启动时所有的配置都会被打包进来。


IDEA profiles.png

4、maven 命令测试

命令执行打包: mvn clean package -Dmaven.test.skip=true -P标识

例(local环境打包测试): mvn clean package -Dmaven.test.skip=true -Plocal

5、效果:

maven profile效果.png

相关文章

  • Maven Profile多环境打包

    在项目管理中,对于一个项目或者产品,我们经常会有开发,测试,预发布,生产等多套环境。为避免每次打包发布有过多的人为...

  • maven profile 打包多环境

    说明:spring + maven 的项目结构图: 前提:spring-mvc.xml 引入.properties...

  • maven profile多环境配置

    使用maven profile实现多环境配置(代码) maven profile 实现多环境可移植构建 在开发过程...

  • Maven Profile按环境打包

    在日常开发中,我们项目的开发环境和生产环境以及测试环境往往是不同的,比如:数据库的url等。在项目上生产环境时,就...

  • 5.SpringBoot多环境配置

    maven多环境配置示例 SpringBoot多环境配置 Profile是Spring针对不同环境不同配置的支持。...

  • Maven 多环境打包以及聚合打包(一)

    说明 本文只是一个总结参考文章:Maven 插件 - 打包时多环境配置文件设置 Maven 多环境打包 mav...

  • Spring Profile

    Maven打包通过Profile来区分环境所需的配置; 1.pom.xml文件内配置: 2.application...

  • 2020-03-19 springboot 打包运行

    打包 指定profile mvn clean package -Pbeta 指定profile以maven命令的方...

  • maven多环境profile配置

    在实际开发项目中,常常有几种环境,一般情况下最少有三种环境:开发、测试、正式。 各个环境之间的参数各不相同,比如m...

  • Maven jar profile 多环境

    简言 为了减少开发人员反复修改配置,考虑在旧项目(非springboot)中使用 maven profile,在此...

网友评论

      本文标题:maven profile 打包多环境

      本文链接:https://www.haomeiwen.com/subject/rshbvctx.html