Topic
4 replies Latest Post - ‏2013-11-19T14:58:44Z by Pich
Pich
Pich
9 Posts
ACCEPTED ANSWER

Pinned topic java.lang.NoClassDefFoundError: org/w3c/dom/Node, org/w3c/dom/Document

‏2013-11-14T20:08:14Z |

I am having a runtime error in org.w3c.dom package while starting up a web app in WLP, I tried several things with no success so far, if i import the package in the web gundle:

Import-package:  org.w3c.dom

It is wired succesfully:

        (w) [web_2.0.0]:org.w3c.dom -> [org.eclipse.osgi_3.8.2]:org.w3c.dom

When i try to run the application:

[ERROR   ] SRVE0283E: Exception caught while initializing context: java.lang.NoClassDefFoundError: org.w3c.dom.Node
    at java.lang.J9VMInternals.verifyImpl(Native Method)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:93)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:91)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:91)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:91)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:170)
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Class.java:182)
....

If i remove it from the import-package and try to  it get it from the Bundle-classpath and of course put the jar in the lib location:

Bundle-ClassPath:  WEB-INF/lib/javax.xml_1.3.4.v201005080400.jar

[ERROR   ] SRVE0283E: Exception caught while initializing context: java.lang.LinkageError: loading constraint violation: loader "org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader@72c03c35" previously initiated loading for a different type with name "org/w3c/dom/Document" defined by loader "com/ibm/oti/vm/BootstrapClassLoader@73988aef"
    at java.lang.ClassLoader.defineClassImpl(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:295)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
    at [internal classes]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:690)
...

   at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2220)
    at [internal classes]

[ERROR   ] SRVE0283E: Exception caught while initializing context: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/w3c/dom/Document

[ERROR   ] Uncaught.init.exception.thrown.by.servlet.RestServlet                                                                                                               org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/w3c/dom/Document


If i remove both:

[ERROR   ] SRVE0283E: Exception caught while initializing context: java.lang.NoClassDefFoundError: org.w3c.dom.Document
...
    at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2220)
    at [internal classes]

[ERROR   ] Context initialization failed
Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org.w3c.dom.Node
[ERROR   ] SRVE0283E: Exception caught while initializing context: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org.w3c.dom.Node
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2220)
    at [internal classes]
Caused by: java.lang.NoClassDefFoundError: org.w3c.dom.Node
    at java.lang.J9VMInternals.verifyImpl(Native Method)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:93)
    at java.lang.J9VMInternals.prepare(J9VMInternals.java:490)
    at java.lang.Class.getDeclaredConstructor(Class.java:492)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createBeanDefinitionDocumentReader(XmlBeanDefinitionReader.java:505)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:491)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    ... 15 more

Any help is really appreciated. Thanks
 

  • MarkN
    MarkN
    10 Posts
    ACCEPTED ANSWER

    Re: java.lang.NoClassDefFoundError: org/w3c/dom/Node, org/w3c/dom/Document

    ‏2013-11-15T10:43:11Z  in response to Pich

    Hi Pich, 

    I am having a runtime error in org.w3c.dom package while starting up a web app in WLP

    I think you're writing an OSGi application, is that correct?

    I have just checked that I can construct a class that implements Node in a simple OSGi application. I can do so, which is encouraging. 

    > > i import the package in the web gundle:

    I think this is likely your problem. At the top of your stack trace we see, 

    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions

    Can you please add the

    Import-Package: org.w3c.dom

    statement to the bundle containing this Spring code? That this needs to be done is troubling because it suggests that you're using non-OSGi friendly Spring code in an OSGi application. You might also want to investigate whether the Spring code you're using also comes in a well-formed OSGi bundle form. If not, you may well encounter a range of further problems as you OSGi-ify your Spring libraries. 

    Regards, 

    Mark

    • Pich
      Pich
      9 Posts
      ACCEPTED ANSWER

      Re: java.lang.NoClassDefFoundError: org/w3c/dom/Node, org/w3c/dom/Document

      ‏2013-11-15T17:39:09Z  in response to MarkN

      I just put the log I got in the cases I tried, I also put the log i got when I add the import-package as you suggest. Since I suspected that the spring dependency injection will cause trouble in an osgi environment, I didn't place the spring jars as separate bundles but in the same web bundle as an entry in the bundle-classpath. So the spring jars and the org.w3c.dom package shold be loaded in the web bundle classloader.

      Import-package:  org.w3c.dom

      It is wired succesfully:

              (w) [web_2.0.0]:org.w3c.dom -> [org.eclipse.osgi_3.8.2]:org.w3c.dom

      When I try to run the application:

      [ERROR   ] SRVE0283E: Exception caught while initializing context: java.lang.NoClassDefFoundError: org.w3c.dom.Node
          at java.lang.J9VMInternals.verifyImpl(Native Method)
          at java.lang.J9VMInternals.verify(J9VMInternals.java:93)
          at java.lang.J9VMInternals.verify(J9VMInternals.java:91)
          at java.lang.J9VMInternals.verify(J9VMInternals.java:91)
          at java.lang.J9VMInternals.verify(J9VMInternals.java:91)
          at java.lang.J9VMInternals.initialize(J9VMInternals.java:170)
          at java.lang.Class.forNameImpl(Native Method)
          at java.lang.Class.forName(Class.java:182)

      This happens on the web bundle, I really think that the problem is the java.langClass.forName, if I inspect its class loader, it returns null. I tried using global shared libraries so org.w3c.dom package is visible in java.lang.Class but no success either.

      A workaround I did was replacing that line of code:  pageClass = Class.forName( pageClassName ); 

      for:  pageClass = webClassLoader.loadClass( pageClassName );

      That did the trick, the bunch of exepctions regarding org.w3c.dom gone (I still have others not related to this I think), but I don't know if might have issues in the future since I know they have differences.

      • MarkN
        MarkN
        10 Posts
        ACCEPTED ANSWER

        Re: java.lang.NoClassDefFoundError: org/w3c/dom/Node, org/w3c/dom/Document

        ‏2013-11-18T09:46:22Z  in response to Pich

        Hi Pich, 

        I'm glad that you're making progress. Was there ever a ClassNotFound exception reported as the cause of the NoClassDefFound errors?

        Regards, 

        Mark

        • Pich
          Pich
          9 Posts
          ACCEPTED ANSWER

          Re: java.lang.NoClassDefFoundError: org/w3c/dom/Node, org/w3c/dom/Document

          ‏2013-11-19T14:58:44Z  in response to MarkN

          Hi MarkN

          Not for this class. In the bundle where I perform the Class.forName I imported the package and it seems to be resolved successfully as pasted above.

          However, if I turn on the debug flags for class loading I can see several ClassNotFoundExceptions for many internal classes:

          java.lang.ClassNotFoundException: org.apache.felix.shell.Command

          java.lang.ClassNotFoundException: org.apache.aries.proxy.weaving.WovenProxy

          java.lang.ClassNotFoundException: org.osgi.service.blueprint.container.BlueprintContainer

          java.lang.ClassNotFoundException: org.apache.aries.proxy.InvocationListener

          java.lang.ClassNotFoundException: com.ibm.ws.jsp.resources.messages_en_US (an many other message-like exceptions)