maven中使用不同配置文件打包

项目中经常会把项目部署到多个环境,例如本地和远程生产环境。
如果每次部署之前都手动修改配置文件会显得太土锤,maven的profile正好可以解决此类问题。
直接上实例:

pom.xml

<profiles>
        <profile>
            <!-- 本地环境 -->
            <id>local</id>
            <properties>
                <jdbcUrl>jdbc:postgresql://127.0.0.1/cloudData</jdbcUrl>
                <dataFileOutputPath>E:\\dataMigration</dataFileOutputPath>
                <quartzUrl>jdbc:postgresql://127.0.0.1:5432/quartz</quartzUrl>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>

        <profile>
            <!-- 生产环境 -->
            <id>production</id>
            <properties>
                <jdbcUrl>jdbc:postgresql://***.**.**.***/GPSData</jdbcUrl>
                <dataFileOutputPath>D:\\dataMigration</dataFileOutputPath>
                <quartzUrl>jdbc:postgresql://***.**.**.***:5432/quartz</quartzUrl>
            </properties>
        </profile>
    </profiles>

配置文件中以占位符标识变量:

jdbcUrl=${jdbcUrl}

# dataFile path
dataFileOutputPath=${dataFileOutputPath}

打包时指定profile,配置文件中的变量即可被替换

maven package -P local
或
maven package -P production
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值