Search code examples
mavenmaven-resources-plugin

Maven resource plugin expose an image from a different path


I have an immage accessible from /resources/gfx/loading.gif

I would like to have it accessible from /img/immage.gif

I tried with maven-resources-plugin with the following config, but actualy nothing happens.

I'm curretnly building the app from eclipse.

 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
            <execution>
                <id>copy-loading-status</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>/src/main/webapp/img</outputDirectory>
                    <resources>
                        <resource>
                            <directory>/src/main/resources/gfx</directory>
                            <includes>
                                <include>loading.gif</include>
                            </includes>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>

Solution

  • Assuming you are building a WAR, you could configure the maven-war-plugin to include additional web resources:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <webResources>
                <resource>
                    <directory>/src/main/resources/gfx</directory>
                    <includes>
                        <include>loading.gif</include>
                    </includes>
                    <targetPath>img</targetPath>
                </resource>
            </webResources>
        </configuration>
    </plugin>