maven 根據不同環境 不同配置

pom 內容

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

<profiles>

    <profile>
        <id>develop</id>
        <properties>
            <env>develop</env>
        </properties>
    </profile>

    <profile>
        <id>test</id>
        <properties>
            <env>test</env>
        </properties>
    </profile>

    <profile>
        <id>product</id>
        <properties>
            <env>product</env>
        </properties>
    </profile>

</profiles>

src/main/filters/filter-develop.properties內容(輔助)

jdbc.url=jdbc:mysql://localhost:3306/dev?characterEncoding=utf-8
jdbc.username=rootdev
jdbc.password=rootdev

src/main/filters/filter-test.properties內容(輔助)

jdbc.url=jdbc:mysql://111.111.111.111:3306/test?characterEncoding=utf-8
jdbc.username=roottest
jdbc.password=roottest

src/main/filters/filter-product.properties內容(輔助)

jdbc.url=jdbc:mysql://121.121.121.121:3306/product?characterEncoding=utf-8
jdbc.username=rootproduct
jdbc.password=rootproduct

src/main/resources/jdbc.properties內容(主要)

url=${jdbc.url}
username=${jdbc.username}
password=${jdbc.password}

maven命令(主要)

mvn package -Pproduct
mvn package -Ptest  
mvn package -Pdevelop
-- 運行打包命令maven會將src/main/filters/filter-${env}.properties對應文件裏的key的值替換到src/main/resources下所有文件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章