Maven_profile_使用profile配置不同环境的properties(实践)

本文详细介绍如何通过Maven的profiles及build节点配置环境变量,并在XML和properties文件中使用这些变量,最后通过Maven命令使配置生效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

配置方法分为以下几个步骤:
1、配置profiles节点(pom.xml)
2、配置build节点(pom.xml)-- 如果不配置该节点则无法找到profile中的properties属性值,并且配置后超链接才有效
3、使用(在xml或properties中使用)

4、执行maven命令,使profiles的local节点生效



1、配置profiles节点(pom.xml)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
< profiles >
        < profile >
            < activation >
               <!-- <os>
                    <family>Windows</family>
                </os>-->
                < activeByDefault >true</ activeByDefault >
            </ activation >
            < id >local</ id >
            < properties >
                < dubbo.registry.address >10.6.1.1:2181</ dubbo.registry.address >
                < jdbc.passwod ></ jdbc.passwod >
            </ properties >
        </ profile >
        < profile >
            < id >test</ id >
            < properties >
                < dubbo.registry.address >10.6.14.11:2181</ dubbo.registry.address >
            </ properties >
        </ profile >
    </ profiles >


2、配置build节点(pom.xml)

1
2
3
4
5
6
7
8
9
10
11
12
13
< build >
        < resources >
            < resource >
                < directory >${project.basedir}/src/main/resources</ directory >
                < filtering >true</ filtering >
            </ resource >
            < resource >
                < directory >${project.basedir}/bin</ directory >
                < targetPath >/bin</ targetPath >
                < filtering >true</ filtering >
            </ resource >
        </ resources >
    </ build >


3、使用(在xml或properties中使用)

a) xml文件中使用

  <dubbo:registry protocol="zookeeper" address="${dubbo.registry.address}"/>

b) properties文件中使用

jdbc.password=${jdbc.passwod}


4、执行maven命令,使profiles的local节点生效

install -P local -DskipTests












评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值