简体   繁体   English

将Maven WAR插件与配置文件一起使用

[英]Using Maven WAR Plugin with Profiles

I'm trying to get images to my Maven web-application according to the profile selected at build time. 我试图根据构建时选择的配置文件将图像发送到我的Maven Web应用程序。 But I keep on getting the whole folder of all the profiles to the point where I need the images to go. 但是我一直将所有配置文件的整个文件夹放到需要图像的位置。

<build>
    <finalName>user-interface</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <webResource>
                        <directory>src/main/profile/webapp/</directory>
                        <targetPath>images</targetPath>
                    </webResource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>user</id>
    </profile>
    <profile>
        <id>dev</id>
    </profile>
</profiles>

How to fix this? 如何解决这个问题? Default image is banner.jpg and both profiles have respective images in correct order. 默认图像为banner.jpg并且两个配置文件均具有正确顺序的图像。 Inside src/main/profile/webapp/ there are 2 folders user and dev with each having images folder and the banner.jpg inside images folder. src/main/profile/webapp/ ,有两个文件夹userdev ,每个文件夹都有images文件夹和banner.jpg文件夹。

You need to define a custom property inside each profile and then reference that property in the configuration of the plugin: 您需要在每个配置文件中定义一个自定义属性,然后在插件的配置中引用该属性:

<build>
    <finalName>user-interface</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <webResource>
                        <directory>src/main/profile/webapp/${banner.folder}</directory>
                        <targetPath>images</targetPath>
                    </webResource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>user</id>
        <properties>
            <banner.folder>user</banner.folder> <!-- defines banner.folder property when the user profile is activated -->
        </properties>
    </profile>
    <profile>
        <id>dev</id>
        <properties>
            <banner.folder>dev</banner.folder> <!-- defines banner.folder property when the dev profile is activated -->
        </properties>
    </profile>
</profiles>

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

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