0

我正在尝试根据构建时选择的配置文件将图像获取到我的 Maven Web 应用程序。但我不断将所有配置文件的整个文件夹放到我需要图像的位置。

<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>

如何解决这个问题?默认图像是banner.jpg,并且两个配置文件都以正确的顺序具有各自的图像。里面src/main/profile/webapp/有 2 个文件夹userdev每个文件夹都有图像文件夹和banner.jpg内部图像文件夹。

4

1 回答 1

3

您需要在每个配置文件中定义一个自定义属性,然后在插件的配置中引用该属性:

<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>
于 2015-09-15T13:29:32.647 回答