LaVOZs

The World’s Largest Online Community for Developers

'; java - How to exclude an xml file in a maven jar dependency - LavOzs.Com

My project uses a jar that contains a file named broker.xml. Also I have a second file with the same name broker.xml in the resource folder. When I run the web application, I get an error "duplicates non mergeable resource broker.xml".

Is there a way to exclude the xml file inside the jar?

Try TrueZIP Maven Plugin, looks like it suits your scenario

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>truezip-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <id>remove-a-file-in-sub-archive</id>
            <goals>
                <goal>remove</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <fileset>
                    <directory>target/Samplewebapp.war/WEB-INF/lib/someJar.jar</directory>
                    <includes>
                        <include>broker.xml</include>
                    </includes>
                </fileset>
            </configuration>
        </execution>
    </executions>
</plugin>

refer to below link for documentation

http://www.mojohaus.org/truezip/truezip-maven-plugin/

http://www.mojohaus.org/truezip/truezip-maven-plugin/remove-mojo.html

Also refer to below stackoverflow link (look at answer from @Andrea) Remove file from dependency jar using maven

Related
How do I tell Maven to use the latest version of a dependency?
Can I add jars to maven 2 build classpath without installing them?
How can I create an executable JAR with dependencies using Maven?
'Must Override a Superclass Method' Errors after importing a project into Eclipse
How to add local jar files to a Maven project?
IntelliJ inspection gives “Cannot resolve symbol” but still compiles code
SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”
Can't execute jar- file: “no main manifest attribute”
Dealing with “Xerces hell” in Java/Maven?
How to add local .jar file dependency to build.gradle file?