Maven ProfileFilter 分环境运行

本文介绍如何使用Maven配置不同环境(如开发、测试和生产环境)的属性文件,并通过示例展示如何让filter.properties文件中的url参数自动匹配对应环境的url值。

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

<filters>
            <filter>src/filters/${active.profile}.properties</filter>
        </filters>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <active.profile>dev</active.profile>
            </properties>
            <!-- 把当前profile设置为默认profile,可以同时这是多个为默认-->
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <active.profile>test</active.profile>
            </properties>
        </profile>
        <profile>
            <id>product</id>
            <properties>
                <active.profile>product</active.profile>
            </properties>
        </profile>
    </profiles>

src/filters/下有dev.properties、test.properties、product.properties三个文件,里面都只配置了url一个参数

在src/main/resource下有一个filer.properties文件,里面一个参数url=${url}

termina里面运行:mvn clean package -Pdev

之后filter.properties里的url会自动匹配到之前之前的dev.properties里的url值

详见文章:https://segmentfault.com/a/1190000003908040

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值