Announcement Announcement Module
Collapse
No announcement yet.
NoClassDefFoundError while instantiating classes implementing POJI from ext. jars Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • NoClassDefFoundError while instantiating classes implementing POJI from ext. jars

    Hello there,

    being pretty new to spring source I apologize for a maybe dumb question in advance.

    In my ear application I am using spring-2.5 as a DI-container to dynamically include classes from an jar which resides outside the ear container [using weblogic 10.3 as an application server]. While locating a class from the external jar works fine having included the corresponding file in the system classpath, its instantiation fails as the class to instantiate implements an interface which itself resides an jar within the ear container.

    external jar:
    class classWithinJar implements qualified.className.of.class.within.ear /* instantiated via spring-beans-xml */
    ear jar:
    interface qualified.className.of.class.within.ear

    The Stacktrace reads:

    javax.ejb.EJBException: nested exception is: org.springframework.beans.factory.CannotLoadBeanCl assException: Error loading class [classWithinJar] for bean with name 'classWithinJarBean' defined in class path resource [spring-beans.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: qualified.className.of.class.within.ear
    org.springframework.beans.factory.CannotLoadBeanCl assException: Error loading class [qualified.className.of.class.within.jar.classWithi nJar] for bean with name 'classWithinJarBean' defined in class path resource [spring-beans.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: qualified/className/of/class/within/ear
    at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1144)
    at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1105)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:386)
    at java.security.AccessController.doPrivileged(Native Method)
    (... *snipped*)

    As you can see, I adopted the class references a bit to protect the innocent :-)

    To me, this looks like a classLoaderIssue even though I don't understand why the ear-class is not found by the spring-instantiated class. Maybe someone can clarify on the issue of classpathes here?

    I debugged into my application and got the following classLoader-order:

    1. sun.misc.Launcher (ExtClassLoader)
    2. sun.misc.Launcher (AppClassLoader)
    3. java.net.URLClassLoader
    4. weblogic.utils.classloaders.GenericClassLoader
    5. weblogic.utils.classloaders.FilteringClassLoader
    6. weblogic.utils.classloaders.GenericClassLoader

    Any feedback will be greatly appreciated!

  • #2
    Bean not found in separate library

    Hi!

    Have you found any solution to your problem?
    I might be having a similar problem myself.

    Please see the configuration of the project bellow:

    Code:
    smth.ear
     |
     +- smth.war
         |
         +- WEB-INF
             |
             +- lib
                 |
                 +- libA.jar
                 |   + common-beans.xml
                 |   + com.a.b.c (package)
                 |      + BaseClass.class
                 |      + ImplClass_1.class |
                 |      + ImplClass_2.class | - BaseClass is visible and the beans are instantiated
                 |      + ImplClass_2.class |
                 |
                 +- libB.jar
                     + implClass_4-beans.xml
                     + com.x.y.z (package)
                        + ImplClass_4.class - BaseClass is NOT visible and I get the following error
    The error I get is:

    Code:
    Context initialization failed
    org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.x.y.z.ImplClass_4] for 
    bean with name 'implClass_4' defined in class path resource [implClass_4-beans.xml]: problem with class file or 
    dependent class; nested exception is java.lang.NoClassDefFoundError: com/a/b/c/BaseClass
    The bean definition for BaseClass is written in common-beans.xml which is placed in libA.jar:

    Code:
    <bean abstract="true" id="abstractBaseClass" class="com.a.b.c.BaseClass">
    The bean definition for ImplClass_4 is written in implClass_4-beans.xml which is placed in libB.jar:
    Code:
    <bean id="implClass_4" class="com.x.y.z.ImplClass_4" parent="abstractBaseClass">
    Any suggestions are welcome.

    Thanks in advance!

    Comment


    • #3
      I have found the issue behind this error.

      The problem was that I had duplicate libraries in the package:
      - I had one set of libraries, including libB.jar in smth.ear/lib
      - I had almost the same set of libraries, including libB.jar and libA.jar in smth.ear/smth.war/WEB-INF/lib

      So something like this:

      Code:
      smth.ear
       |
       +- lib
       |   + lib1.jar
       |   + lib2.jar
       |   + spring_lib.jar
       |   ...        
       |   + libB.jar  (but not libA.jar)
       |
       +- smth.war
           |
           +- WEB-INF
               |
               +- lib
                   + lib1.jar
                   + lib2.jar
                   + spring_lib.jar
                   ...
                   + libA.jar
                   + libB.jar
      After removing all the duplicate libs from smth.ear/lib, the project deployed and started correctly.

      Comment

      Working...
      X