Search code examples
mavenpom.xmlmaven-resources-plugin

maven resources plugin flat copy of resources


Given a folder 'database' containing JAR-connectors for different RDBMS. Each JAR is located in its own folder:

+---database
    +---db2
        +---db2.jar
    +---derby
        +---derby.jar
    +---h2
        +---h2.jar
    +---mysql
        +---mysql.jar

I need all of those JAR-files to be copied into WEB-INF\lib.

Here's my pom.xml:

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <webResources>
                    <resource>
                        <directory>../target/${project.artifactId}/classes/database</directory>
                        <targetPath>WEB-INF/lib</targetPath>
                        <includes>
                            <include>**/*.jar</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
</build>

Problem is, that those JARs are copied with their directories:

+---WEB-INF/lib
    +---db2
        +---db2.jar
    +---derby
        +---derby.jar
    +---h2
        +---h2.jar
    +---mysql
        +---mysql.jar

This is how it should be:

+---WEB-INF/lib
    +---db2.jar
    +---derby.jar
    +---h2.jar
    +---mysql.jar

I have 20 connectors and I don't want to hard code them.


Solution

  • The most correct way of doing so will be to install your jar files into Maven repository and then use maven-dependency-plugin:copy goal. Or if you want to solve this roughly then use maven-antrun-plugin (copy rule).