Sometime we face NoSuchMethodError exception in production environment. One of the root cause of this exception is same class exist in two different jar. But particular method is not present in the loaded class.
Lets explain with an example below exception says method readWSDL is not available in WSDLReader class.
In my project WSDLReader class was available in two different jars namely axis-wsdl4j-1.5.1.jar and wsdl4j-1.6.2.jar. WSDLReaderinside axis jar doesn't have the method readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;). So we can exclude axis jar from pom and use only wsdl4j-1.6.2.jar.
Exception:
java.lang.NoSuchMethodError: javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition;
POM changes:
dependency>
Lets explain with an example below exception says method readWSDL is not available in WSDLReader class.
In my project WSDLReader class was available in two different jars namely axis-wsdl4j-1.5.1.jar and wsdl4j-1.6.2.jar. WSDLReaderinside axis jar doesn't have the method readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;). So we can exclude axis jar from pom and use only wsdl4j-1.6.2.jar.
Exception:
java.lang.NoSuchMethodError: javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition;
POM changes:
<dependency>
<groupId>com.ExampleService</groupId>
<artifactId>service</artifactId>
<exclusions>
<exclusion>
<artifactId>axis-wsdl4j</artifactId>
<groupId>axis</groupId>
</exclusion>
</exclusions>
</dependency
Thanks. Useful post!
ReplyDeleteIt is really useful.
ReplyDeleteI faced similar problem. In my case in tomcat directory i removed wsdl4j jar.
becoz thats available in cxf project lib itself.
so same readwsdl method in both jars.
so removed one from tomcat directory.
finally works fine.
useful post
ReplyDeleteAre you sure readWSDL doesn't exist in axis-wsdl4j-1.5.1.jar? I do SEE a reference to it on java\wsdl\xml\WSDLReader.class...
ReplyDelete