maven resources plugin flat copy of resources

2019-08-11 00:24发布

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.

2条回答
老娘就宠你
2楼-- · 2019-08-11 00:49

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

查看更多
爷、活的狠高调
3楼-- · 2019-08-11 01:02

You're having problems because you're trying to bend maven into something it's not supposed to do. Binary artifacts should be deployed into your artifacts repository (or local maven repository) and not included into your project. This way having them defined as dependencies in pom would ensure that they're copied into your WEB-INF/lib.

查看更多
登录 后发表回答