3

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?

user685673
  • 301
  • 2
  • 6

3 Answers3

0

The short answer is NO

But, if you wish to use your own log4j configuration set the System Property named log4j.configuration using -Dlog4j.configuration=somefile.properties or similar.

See this SO-answer for more info.

Community
  • 1
  • 1
wassgren
  • 18,651
  • 6
  • 63
  • 77
0

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>
Dário
  • 2,002
  • 1
  • 18
  • 28
cosmos
  • 2,143
  • 2
  • 17
  • 27
-2

Use

<dependency>
  <groupId>sample.ProjectA</groupId>
  <artifactId>Project-A</artifactId>
  <version>1.0</version>
  <scope>compile</scope>
  <exclusions>
    <exclusion>  <!-- declare the exclusion here -->
      <groupId>sample.ProjectB</groupId>
      <artifactId>Project-B</artifactId>
    </exclusion>
  </exclusions> 
</dependency>
  • 1
    If I'm not mistaken. This excludes a dependency, not a resource in Project-A which was what the OP asked for? – wassgren Dec 21 '14 at 17:06