首页 > 其他 > 详细

maven学习之不同环境打包不同文件夹下的配置文件

时间:2019-12-13 11:50:42      阅读:327      评论:0      收藏:0      [点我收藏+]

 

1.src/main/resources下创建test和produce文件夹,添加对应的属性文件。

2.src/main/resources下创建默认的开发属性文件。

 <build>
  <plugins>
  <!-- 不同环境的配置文件选择 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</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>
                                    <!-- 指定resources插件处理哪个目录下的资源文件 -->
                                    <directory>src/main/resources/${package.environment}</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                        <inherited></inherited>
                    </execution>
                </executions>
            </plugin>
  </plugins>
   <resources>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>test/**</exclude>
                    <exclude>product/**</exclude>
                </excludes>
                <filtering>true</filtering>
            </resource>
        </resources>
  </build>
    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <package.environment>dev</package.environment>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <package.environment>test</package.environment>
            </properties>
        </profile>
        <profile>
            <id>product</id>
            <properties>
                <package.environment>product</package.environment>
            </properties>
        </profile>
    </profiles>

maven学习之不同环境打包不同文件夹下的配置文件

原文:https://www.cnblogs.com/yjwfcs/p/12033936.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!