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>

你可能感兴趣的:(maven)