Frage

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.

War es hilfreich?

Lösung

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>

Andere Tipps

Looks like (for Debug mode in IDEA) just switching depenencies order solved the issue.

How it was:

    <dependency>
        <groupId>my.naughty.thirdparty</groupId>
        <artifactId>thirdparty-ref-log4j-over-slf4j</artifactId>
        <version>0.50</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>apache-log4j-extras</artifactId>
        <version>1.1</version>
    </dependency>

Changed to:

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>apache-log4j-extras</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>my.naughty.thirdparty</groupId>
        <artifactId>thirdparty-ref-log4j-over-slf4j</artifactId>
        <version>0.50</version>
    </dependency>

But surely I can't consider it as a robust solution, especially for Onejar.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top