Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude resources from a dependent jar with Maven

I have a third party jar file that I have to use, but unfortunately it contains an embedded log4j configuration file as a resource. When I include the third party jar as a Maven dependency, I also pick up their log4j configuration, which overrides my own.

Is there a way to tell Maven to include a jar dependency, while excluding a specific resource within that jar?

like image 335
user685673 Avatar asked Jan 28 '26 15:01

user685673


1 Answers

Yes, you can use maven shade plugin for that. You can use filters to exclude the resource.

A working example of how to achieve this:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>${maven.shade.plugin.version}</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>logback.xml</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>
like image 62
cosmos Avatar answered Jan 31 '26 06:01

cosmos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!