ITPub博客

首页 > IT职业 > IT图书 > maven profile filter 线上线下分开打包配置

maven profile filter 线上线下分开打包配置

IT图书 作者:winnie324 时间:2021-09-09 09:52:45 0 删除 编辑

maven自动选择不同的配置文件打包profile+filter

1. profile:
[要点:] activeByDefault默认激活,不用再mvn命令时指定额外参数;[注意:] 使用非默认的配置,要在编译时指定:如,要在生产环境打包[并跳过单元测试]:mvn clean package -Pproduct [-Dmaven.test.skip=ture]

如果mvn clean package:

a. 默认加载profile-dev.properties来打包
b. 可以替换的内容范围是:
src/main/resources/*.xml|*.properties...src/main/java/*.xml
            project-name        <!-- 启用filter功能为resources中的变量赋值 -->                                          src/main/resources                                            **/*                                        true                                          src/main/java                                    **/*.xml                                                      <!-- 1.开发环境 -->                    dev                            true                                                            profile-dev.properties                                            <!-- 2.测试环境 -->                    test                                                profile-test.properties                                            <!-- 3.UAT环境 -->                    uat                                                profile-uat.properties                                            <!-- 4.生产环境 -->                    product                                                profile-product.properties                                        
2. 用法:

比如profile-dev.properties文件中定义了

mvn.mysql.url.mydb=jdbc:mysql://localhost:3306/mydbmvn.mysql.user.mydb=rootmvn.mysql.pass.mydb=1234

那么可以在其他公用配置文件中使用${}来引用profile-dev.properties中的属性,比如:

(1). db.properties中:
db.url=${mvn.mysql.url.mydb} db.user=${mvn.mysql.user.mydb}db.pass=${mvn.mysql.pass.mydb}
(2)   spring-ds.xml中:(用法1)
                                

spring-ds.xml中,也可以使用这样:(用法2-引用再引用)

                        

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2093/viewspace-2813948/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Css3整理集合干货
请登录后发表评论 登录
全部评论

注册时间:2019-04-16

  • 博文量
    66
  • 访问量
    412