Java – Maven 2 assembly plugin clobbers some META-INF files

javamaven-2spring

I'm using the Maven 2 assembly plug-in to build a jar-with-dependencies and make an executable JAR file. My assembly includes Spring, and the CXF library.

CXF includes copies of META-INF files spring.schemas and spring.handlers which end up clobbering the similar files from the spring-2.5.4 jar.

By hand, I can update those two files within the jar-with-dependencies.

What I'm looking for is some way in the Maven POM to direct the assembly plug-in to get the correct version of those two files.

The assembly plug-in documentation talks about file filtering, but doesn't seem to have configuration for or parameters, without going to the trouble of creating a custom assembly descriptor.

Is making a custom assembly descriptor my only hope in this instance?

Best Answer

For some reason the solution that Mojo and the others are suggesting still doesn't work for me. I've created my custom spring.handlers and spring.schemas files and put them under src/main/resources/META-INF. However, when using the unpackOptions my files are not included as well. When I don't use the unpackOptions my files aren't the ones in the jar.

What I ended up doing is to reference the files directly. This finally put my files into the JAR.

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <!-- TODO: a jarjar format would be better -->
    <id>jar-with-dependencies</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <unpack>true</unpack>
            <unpackOptions>
                <excludes>
                    <exclude>META-INF/spring.handlers</exclude>
                    <exclude>META-INF/spring.schemas</exclude>
                </excludes>
            </unpackOptions>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
    <files>
        <file>
            <source>${project.basedir}/src/main/resources/META-INF/spring.handlers</source>
            <outputDirectory>META-INF</outputDirectory>
        </file>
        <file>
            <source>${project.basedir}/src/main/resources/META-INF/spring.schemas</source>
            <outputDirectory>META-INF</outputDirectory>
        </file>
    </files>
</assembly>