maven通过Profile实现动态切换配置值

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.mylab.maven</groupId>
    <artifactId>filter-test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <!--是否默认起效-->
                <activeByDefault>false</activeByDefault>

                <!--根据jdk来激活profile-->
                <!--
                在1.4 1.5 1.6时激活: <jdk>[1.4,1.7)</jdk>
                -->
                <jdk>1.8</jdk>
                <!--根据操作系统来激活profile-->
                <os>
                    <name>Windows7</name>
                    <family>Windows</family>
                    <arch>x86-64</arch>
                    <version>6.1.7601</version>
                </os>
                <!--根据系统属性来激活profile
                使用: mvn clean compile –Ddev=true
                如未定义value属性, 则任意值的dev都可以激活
                -->
                <property>
                    <name>dev</name>
                    <value>true</value>
                </property>
                <!--根据文件是否存在激活-->
                <file>
                    <exists>${basedir}/file2.properties</exists>
                    <missing>${basedir}/file1.properties</missing>
                </file>
            </activation>

            <build>
                <filters>
                    <filter>${project.basedir}/profiles/helloFilter.txt</filter>
                </filters>

                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>hello.txt</include>
                        </includes>
                    </resource>
                </resources>
            </build>

        </profile>
    </profiles>

</project>

转载于:https://my.oschina.net/CasparLi/blog/310154

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值