mavenclassloaderslf4jlogbackonejar

Onejar-maven-plugin to set the order of jar loading


I've been using the library apache-log4j-extras for logging. It contains class org.apache.log4j.Logger.

Now I had to reference some 3rd party library, that uses logback and has among its dependencies log4j-over-slf4j (jar). Unfortunately, latter jar also contains class org.apache.log4j.Logger.

Looks like the latter class is preferred by the onejar classloader...

I don't need logback and log4j-over-slf4j. Just want my org.apache.log4j.Logger from apache-log4j-extras back. What are my options with the Onejar-maven-plugin?

EDIT: It appeared to be an issue with Debug mode in IDEA, not with onejar. However the question is still relevant: how can I ensure that I load the requried class with Onejar?

EDIT2: E.g. in C# it could be easily resolved with "extern alias" feature.


Solution

  • why don't you just exclude it?

    <dependency>
        <groupId>my.naughty.thirdparty</groupId>
        <artifactId>thirdparty-with-log4j-over-slf4j</artifactId>
        <version>${thirdparty.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>log4j-over-slf4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>