Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.NoClassDefFoundError when trying a basic webservice using Spring WS 2.0.3

 
Nitin Bhardwaj
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I was just trying a very basic Spring WS, and I am getting NoClassDefFoundError for org.jdom.Parent class. However, I've checked that jdom.jar is present in the WEB-INF/lib of webapp folder (deployed in JBoss 6). I've also checked that jdom.jar doesn't exist in either lib folder of JBoss or in common/lib folder of JBoss.
The Endpoint class that I've written for the Webservice goes as follows:



When I try to view the WSDL by hitting the browser with the following URL:
http://localhost:8080/nitspace/springws/clientCreationService/clientcreation.wsdl
then the JBoss 6 console shows the following error on console:

15:14:55,218 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/nitspace]] Initializing Spring FrameworkSer
vlet 'spring-ws'
15:14:55,375 INFO [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] JSR-250 'javax.annotation.ManagedBean
' found and supported for component scanning
15:14:55,375 INFO [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] JSR-330 'javax.inject.Named' annotati
on found and supported for component scanning
15:14:55,437 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] JSR-330 'javax.inject.Inj
ect' annotation found and supported for autowiring
15:14:56,031 INFO [STDOUT] Hi Nitin...inside BaseDaoJPAImpl-->setEntityManagerFactory(EntityManagerFactory entityManagerFactory
) method=org.jboss.jpa.injection.InjectedEntityManagerFactory@1efeff7
15:14:56,359 INFO [STDOUT] Hi Nitin inside ClientEndpoint() constructor...clientDao set to-->com.nitspace.dao.impl.ClientDao@1b
27c93
15:14:56,375 ERROR [org.springframework.ws.transport.http.MessageDispatcherServlet] Context initialization failed: org.springfra
mework.beans.factory.BeanCreationException: Error creating bean with name 'clientEndpoint' defined in "/D:/servers/jboss-as-6.0.
0/server/default/deploy/nitspace.war/WEB-INF/classes/com/nitspace/springws/client/ClientEndpoint.class": Instantiation of bean f
ailed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.nitspace.
springws.client.ClientEndpoint]: Constructor threw exception; nested exception is org.jdom.JDOMException: java.lang.NoClassDefFo
undError: org/jdom/Parent: org/jdom/Parent
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:288) [:3.0
.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapa
bleBeanFactory.java:1003) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapab
leBeanFactory.java:907) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBean
Factory.java:485) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFa
ctory.java:456) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) [:3.0.5.RELEA
SE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java
:222) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) [:3.0.5.RELEASE
]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFact
ory.java:580) [:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationCon
text.java:895) [:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) [:3.0.5.R
ELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) [:3.0.5.RELEA
SE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) [:3.0.5.RELEA
SE]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) [:3.0.5.RELEASE
]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) [:3.0.5.RELEASE]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) [:3.0.5.RELEASE]
at javax.servlet.GenericServlet.init(GenericServlet.java:242) [:1.0.0.Final]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1208) [:6.0.0.20101110-CR1]
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:955) [:6.0.0.20101110-CR1]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:188) [:6.0.0.20101110-CR1]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.20101110-CR1]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.20101110-CR1
]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:593) [:6.0.0.20101110-CR1]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.20101110-CR1]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:
6.0.0.20101110-CR1]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.20101110-CR1]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.20101110-CR1]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.20101110-CR1]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.20101110-CR1]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)
[:6.0.0.20101110-CR1]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.20101110-CR1]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.20101110-CR1]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [:6.0.0.20101110-CR1
]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.20101110-CR1]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_23]
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.nitspace.springws.client.
ClientEndpoint]: Constructor threw exception; nested exception is org.jdom.JDOMException: java.lang.NoClassDefFoundError: org/jd
om/Parent: org/jdom/Parent
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:10
8) [:3.0.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280) [:3.0
.5.RELEASE]
... 37 more
Caused by: org.jdom.JDOMException: java.lang.NoClassDefFoundError: org/jdom/Parent: org/jdom/Parent
at org.jdom.xpath.XPath.newInstance(XPath.java:146) [:1.1.2]
at com.nitspace.springws.client.ClientEndpoint.<init>(ClientEndpoint.java:44) [:]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [:1.6.0_23]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [:1.6.0_23]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [:1.6.0_23]
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [:1.6.0_23]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) [:3.0.5.RELEASE]
... 39 more
Caused by: java.lang.NoClassDefFoundError: org/jdom/Parent
at org.jaxen.jdom.JDOMXPath.<init>(JDOMXPath.java:91) [:1.1]
at org.jdom.xpath.JaxenXPath.setXPath(JaxenXPath.java:281) [:1.1.2]
at org.jdom.xpath.JaxenXPath.<init>(JaxenXPath.java:99) [:1.1.2]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [:1.6.0_23]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [:1.6.0_23]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [:1.6.0_23]
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [:1.6.0_23]
at org.jdom.xpath.XPath.newInstance(XPath.java:137) [:1.1.2]
... 45 more
Caused by: java.lang.ClassNotFoundException: org.jdom.Parent from BaseClassLoader@154b574{vfs:///D:/servers/jboss-as-6.0.0/serve
r/default/conf/jboss-service.xml}
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480) [jboss-classloader.jar:2.2.0.Alpha
9]
at java.lang.ClassLoader.loadClass(ClassLoader.java:248) [:1.6.0_23]
... 53 more



When I comment the following code inside costructor ClientEndpoint(IClientDao dao) in the above Java class ClientEndpoint:


then I am able to view the WSDL by hitting the browser with the following URL perfectly fine:
http://localhost:8080/nitspace/springws/ClientCreationService/clientcreation.wsdl

I can provide WSDL, XSD, and spring-ws-servlet.xml if those files are needed for this issue. However, I think it may be a JAR issue unrelated to coding.

Best Regards,
Nitin
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like a classloader issue.

Caused by: java.lang.ClassNotFoundException: org.jdom.Parent from BaseClassLoader@154b574{vfs:///D:/servers/jboss-as-6.0.0/serve
r/default/conf/jboss-service.xml}

It looks like it is looking for the class in the JBoss server's classloader, not in your app's classloader. Since you app's classloader is a child of the server's classloader, the child can see the classes in the parent, but not the other way around. So therefore the server classloader will not see classes in your app's lib directory.

It looks like you need to move the jar file into the default server lib directory or vfx:///D:/servers/jboss-as-6.0.0/server/default/lib directory.

See if that works.

Mark
 
Nitin Bhardwaj
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks Mark, it worked ! But I've a question: The Web-Application's classloader being the child classloader should have been given a chance to load the class (when JBoss classloader failed) then why the application's classloader also failed to load the jdom.jar given the fact that it was already present in the application's WEB-INF/lib directory?

Best Regards,
Nitin
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran into (similar) issue a few days ago, to cut a long story short the problem happens if a class loaded by the Parent class loader (Jboss WEB-INF) tries to access a class that is available in the child class loader (application WEB-INF/lib)
In your case the XPath lib was loaded by the Parent class loader and so any classes it needs should also be available in the same class loader.

All of this is a bit of a pain, but that's how it is!

Update
Mark has summed it up well,

Since you app's classloader is a child of the server's classloader, the child can see the classes in the parent, but not the other way around.
 
Nitin Bhardwaj
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Mercs wrote:..... the problem happens if a class loaded by the Parent class loader (Jboss WEB-INF) tries to access a class that is available in the child class loader (application WEB-INF/lib)
In your case the XPath lib was loaded by the Parent class loader and so any classes it needs should also be available in the same class loader.


Thanks Sam ...now I can relate Mark's comment to the problem that I faced.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic