18

I am getting this exception while trying to call SOAP webservice using axis. basically I have written a axis client.

org.apache.commons.discovery.DiscoveryException: Class org.apache.commons.logging.impl.SLF4JLogFactory does not implement org.apache.commons.logging.LogFactory.

When I remove the all the common-logging jars, I would able to remove these errors but these jars are coming from other apis, i dont have control on them.

Is there any way to overcome this problem?

Maneesh Kumar
  • 1,367
  • 2
  • 9
  • 13
  • Probably the best solution is given below. But if you are using maven project then you can remove the commons-logging by exclusion. axis axis 1.4 commons-logging commons-logging – Purushothaman May 09 '17 at 12:09

6 Answers6

12

There is a pretty detailed explanation of what the issue may be and ways to debug it in the commons logging documentation. Your particular issue may be,

There is also another more unusual way in which this cast can fail: even when the binary is compatible, the implementation class loaded at runtime may be linked to a different instance of the LogFactory class. For more information, see the tech guide.

sbridges
  • 24,960
  • 4
  • 64
  • 71
8

None of this solutions worked for me. I figure out my solution in SLF4J documentation

http://slf4j.org/faq.html#excludingJCL

alternative 2) provided scope Commons-logging can be rather simply and conveniently excluded as a dependency by declaring it in the provided scope within the pom.xml file of your project. The actual commons-logging classes would be provided by jcl-over-slf4j. This translates into the following pom file snippet:

<dependency>  
   <groupId>commons-logging</groupId>  
   <artifactId>commons-logging</artifactId>
   <version>1.1.1</version>  
   <scope>provided</scope>
</dependency> 

<dependency>
   <groupId>org.slf4j</groupId>  
   <artifactId>jcl-over-slf4j</artifactId>
   <version>1.7.21</version>
</dependency>

The first dependency declaration essentially states that commons-logging will be "somehow" provided by your environment. The second declaration includes jcl-over-slf4j into your project. As jcl-over-slf4j is a perfect binary-compatible replacement for commons-logging, the first assertion becomes true. Unfortunately, while declaring commons-logging in the provided scope gets the job done, your IDE, e.g. Eclipse, will still place commons-logging.jar on your project's class path as seen by your IDE. You would need to make sure that jcl-over-slf4j.jar is visible before commons-logging.jar by your IDE.

SLF4J documentation gives more alternatives, this worked for me.

  • 2
    This should be the accepted answer. Of all the suggestions here, this is the only one that worked for me! – Ahi Tuna Jul 15 '19 at 22:45
7

The Link to the above mentioned Documentation to section "Fixes" suggests to include

 -Dorg.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl

in your setup. For some people it might be easier to include this code instead:

static
{
    System.setProperty(LogFactory.FACTORY_PROPERTY, LogFactory.FACTORY_DEFAULT);
}
oliolioli
  • 91
  • 2
  • 5
0

Replace jcl-over-slf4j jar with commons-logging jar

0

Probably its too late :-) but for me following worked. I am using spring boot and added it as first line in the main methods. More explanation as suggested above is here.

    System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
Karan
  • 752
  • 2
  • 13
  • 34
0

In some cases, the Eclipse IDE automatically adds additional dependencies from plugins when generating Web Service Client classes. To resolve this issue, you need to check the project build path and ensure that there are no other plugin dependencies included, such as Axis, Commons Discovery, JAX-RPC, and others.

To do this, follow these steps:

  • Right-click on your project in Eclipse and select Properties -> Java Build Path -> Libraries TAB.
  • Here, you will see a list of dependencies included in your project's build path.
  • Check for any unwanted plugin dependencies (e.g., axis, commons-discovery, jaxrpc) in the list.
  • If you find any unwanted dependencies, select them and click the Remove button to remove them from the build path.

By removing these unwanted plugin dependencies from the build path, you can ensure that they are not included during the compilation and execution of your project.

Please note that this solution is specific to resolving the issue of unwanted plugin dependencies in the Eclipse IDE when generating Web Service Client classes.

selllami
  • 182
  • 1
  • 13