maven resources plugin flat copy of resources

心不动则不痛 提交于 2019-12-24 05:41:30

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/8729442/maven-resources-plugin-flat-copy-of-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!