简体   繁体   English

如何用不同的资源文件夹配置Maven配置文件?

[英]How to configure Maven profiles with different resources folders?

I'm trying to configure my application to have 2 build profiles: development and production. 我正在尝试将我的应用程序配置为具有2个构建配置文件:开发和生产。 In order to do that, I created two subdirectories under the src/main/resources folder: src/main/resources/development and src/main/resources/production . 为此,我在src / main / resources文件夹下创建了两个子目录: src / main / resources / developmentsrc / main / resources / production Each subdirectory has its own .properties files. 每个子目录都有其自己的.properties文件。

<profiles>
    <profile>
        <id>development</id>
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources/development</directory>
                </resource>
            </resources>
        </build>
    </profile>
    <profile>
        <id>production</id>
        <build>
            <resources>
                <resource>
                    <directory>src/main/resource/production</directory>
                </resource>
            </resources>
        </build>
    </profile>
</profiles>

I build the app with the command mvn install -P ${profile_here} 我使用命令mvn install -P $ {profile_here}构建应用程序

Maven copies the content of the folder related to the chosen profile to the WEB-INF/classes output directory, however the development and production folders are copied as well. Maven将与所选概要文件相关的文件夹的内容复制到WEB-INF / classes输出目录,但是还会复制development和production文件夹。

WEB-INF/classes WEB-INF /类

WEB-INF/classes/development WEB-INF /课程/开发

WEB-INF/classes/production WEB-INF /课程/制作

How can I solve this problem? 我怎么解决这个问题?

Thanks in advance. 提前致谢。

The maven-war-plugin is rather limited when it comes to resources. Maven-war-plugin在资源方面相当有限。 However, you could use the maven-resources-plugin to include/exclude resources like described here: https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html 但是,您可以使用maven-resources-plugin包含/排除如下所述的资源: https : //maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM