Search code examples
javajakarta-mailmechanizeapache-commons-logging

org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy


I am using Birt viewer runtime in my web application along with Mechanize and have used log4j for logging in my application. It all was working fine, but then I used java mailing api in my application and I keep receiving this exception: org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed.

I initially was using mail.jar which was fine, for another requirement in my project, I started using mail.1.3.3.jar and it started throwing this exception. I think there is some jar conflict among Mechanize and latest java mail jars.

I need to use either mail.1.3.3.jar or java-mail-1.4.jar.

Please advice how shall I overcome this ??

Thanks.


Solution

  • I was able to get rid of it.

    Actually, the jar of Mechanize (version 0.11.1) contains pom.xml, which I referred and got enlightened about its usage on HttpClient jars. I used the HTTPClient jars of version 4.2.1 in my web application and it is working now.

    The point to note here is: the pom.xml has a dependency:

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.0.1</version>
        <dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>4.0.1</version>
        <dependency>
    </dependencies>
    
    <profiles>
        <profile>
        <id>latestHttpClient</id>
        <dependencies>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.2.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpmime</artifactId>
                <version>4.2.1</version>
            </dependency>
        </dependencies>
        <profile>
    <profiles>
    

    This seems to be a bottleneck now because on one environment, the old versioned jars are working and on other environment, new ones. :(