使用maven-resources-plugin插件分环境配置

时间:2022-04-29 14:22:53

一、项目目录结构

使用maven-resources-plugin插件分环境配置  使用maven-resources-plugin插件分环境配置

 二、pom文件中引入maven-resources-plugin插件和相关的标签

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <overwrite>true</overwrite>
                        <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources/${active.profile}</directory>
                                <filtering>false</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>dev/*</exclude>
                <exclude>prod/*</exclude>
            </excludes>
            <!--<filtering>true</filtering>-->
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
</build>

 

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <active.profile>dev</active.profile>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <active.profile>prod</active.profile>
        </properties>
    </profile>
</profiles>

 

打包命令:

  mvn clean install -Pdev

  mvn clean install -Pprod

参考:

  1、博客,https://www.cnblogs.com/owenma/p/7999023.html

  2、博客,https://www.cnblogs.com/mahuan2/p/6909521.html