5 Replies Latest reply on Feb 9, 2012 12:33 PM by Dustin S.

    NoClassDefFoundError even though package imported

    Dustin S. Newbie

      Hi,

       

      I keep getting a runtime NoClassDefFoundError error even though the package/class that it says it can't find is imported into the necessary bundle:

       

      The bundle is question requires Apache Java Caching System (JCS). JCS in turn depends on an old concurrent library by Doug Lea. Both bundles are Active on the bus:

       

      [ 222] [Active     ] [            ] [       ] [   60] wrap_mvn_jcs_jcs_1.3 (0)
      [ 234] [Active     ] [            ] [       ] [   60] Concurrent (1.3.4)
      

       

      The bundle that throws the error, properly imports both packages

      wrap_mvn_jcs_jcs_1.3 (222): org.apache.jcs; version="0.0.0"
      wrap_mvn_jcs_jcs_1.3 (222): org.apache.jcs.access.exception; version="0.0.0"
      wrap_mvn_jcs_jcs_1.3 (222): org.apache.jcs.engine.control; version="0.0.0"
      Concurrent (234): EDU.oswego.cs.dl.util.concurrent; version="1.3.4"
      

       

      However, when the Spring ApplicationContext is started and one of the beans runs an @AfterProperties method, it throws:

       

      Exception in thread "SpringOsgiExtenderThread-29" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cachingService': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: EDU/oswego/cs/dl/util/concurrent/Channel
           at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1413)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
           at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
           at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
           at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
           at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
           at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
           at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
           at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
           at java.lang.Thread.run(Thread.java:680)
      Caused by: java.lang.NoClassDefFoundError: EDU/oswego/cs/dl/util/concurrent/Channel
           at org.apache.jcs.engine.control.CompositeCacheManager.configure(CompositeCacheManager.java:303)
           at org.apache.jcs.engine.control.CompositeCacheManager.configure(CompositeCacheManager.java:258)
           at edu.utah.further.core.util.cache.CachingServiceJcsImpl.afterPropertiesSet(CachingServiceJcsImpl.java:86)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:340)
           at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:293)
           at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:130)
           ... 16 more
      Caused by: java.lang.ClassNotFoundException: EDU.oswego.cs.dl.util.concurrent.Channel
           at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
           at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
           at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
           at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
           ... 26 more
      

       

      I've verified that the actual Channel class is included in the jar .. just for my sanity.

       

      Looking at the JCS code, at line 303, it calls this method statically

       

      ThreadPoolManager.setProps( props )
      

       

      ThreadPoolManager imports EDU.oswego.cs.dl.util.concurrent.Channel

       

      I've tried a fragment bundle attached to JCS to expand it's classpath - that didn't work either.

       

      The only way I could get it to work was to embed concurrent in JCS.

       

      Is there a bug with ServiceMix 4.4? This worked previously on ServiceMix 4.2.

       

      Thanks,

      Dustin

        • 1. Re: NoClassDefFoundError even though package imported
          Freeman(Yue) Fang Master

          Hi,

           

          Could you post the result of

           

          osgi:headers JCS_bundle_id

          osgi:headers Concurrent_bundle_id

           

          From what you tell us so far, I can't see JCS bundle already import EDU.oswego.cs.dl.util.concurrent package.

           

          Freeman

          • 2. Re: NoClassDefFoundError even though package imported
            Dustin S. Newbie

            Hi Freeman,

             

            You actually gave me a few ideas and I think I've found the issue.. For some reason, the wrap command marks concurrent as optional. Depending on the order you install the bundles, concurrent may or may not be imported properly:

             

            Installing concurrent first, jcs second - everything is imported correctly.

             

            karaf@root> osgi:install -s mvn:edu.oswego.cs.concurrent/com.springsource.edu.oswego.cs.dl.util.concurrent/1.3.4
            Bundle ID: 215
            karaf@root> osgi:install -s wrap:mvn:jcs/jcs/1.3
            Bundle ID: 216
            karaf@root> imports 216
            OPS4J Pax Logging - API (4): org.apache.commons.logging; version=1.1.1
            OPS4J Pax Logging - API (4): org.apache.commons.logging; version=1.0.4
            Commons Pool (56): org.apache.commons.pool.impl; version=1.5.4
            Commons Pool (56): org.apache.commons.pool; version=1.5.4
            Apache ServiceMix :: Bundles :: velocity (66): org.apache.velocity.servlet; version=1.7.0
            Apache ServiceMix :: Bundles :: velocity (66): org.apache.velocity.context; version=1.7.0
            Apache ServiceMix :: Bundles :: velocity (66): org.apache.velocity; version=1.7.0
            Servlet 3.0 (132): javax.servlet; version=2.6.0
            Servlet 3.0 (132): javax.servlet.http; version=2.6.0
            Servlet 3.0 (132): javax.servlet; version=3.0.0
            Servlet 3.0 (132): javax.servlet.http; version=3.0.0
            Concurrent (215): EDU.oswego.cs.dl.util.concurrent; version=1.3.4
            

             

            Installing jcs first, concurrent second - concurrent is not imported. An explicit bundle refresh is required.

             

            karaf@root> osgi:install -s wrap:mvn:jcs/jcs/1.3
            Bundle ID: 215
            karaf@root> osgi:install -s mvn:edu.oswego.cs.concurrent/com.springsource.edu.oswego.cs.dl.util.concurrent/1.3.4
            Bundle ID: 216
            karaf@root> imports 215
            OPS4J Pax Logging - API (4): org.apache.commons.logging; version=1.1.1
            OPS4J Pax Logging - API (4): org.apache.commons.logging; version=1.0.4
            Commons Pool (56): org.apache.commons.pool.impl; version=1.5.4
            Commons Pool (56): org.apache.commons.pool; version=1.5.4
            Apache ServiceMix :: Bundles :: velocity (66): org.apache.velocity.servlet; version=1.7.0
            Apache ServiceMix :: Bundles :: velocity (66): org.apache.velocity.context; version=1.7.0
            Apache ServiceMix :: Bundles :: velocity (66): org.apache.velocity; version=1.7.0
            Servlet 3.0 (132): javax.servlet; version=2.6.0
            Servlet 3.0 (132): javax.servlet.http; version=2.6.0
            Servlet 3.0 (132): javax.servlet; version=3.0.0
            Servlet 3.0 (132): javax.servlet.http; version=3.0.0
            karaf@root> refresh 215
            karaf@root> imports 215
            OPS4J Pax Logging - API (4): org.apache.commons.logging; version=1.1.1
            OPS4J Pax Logging - API (4): org.apache.commons.logging; version=1.0.4
            Commons Pool (56): org.apache.commons.pool.impl; version=1.5.4
            Commons Pool (56): org.apache.commons.pool; version=1.5.4
            Apache ServiceMix :: Bundles :: velocity (66): org.apache.velocity.servlet; version=1.7.0
            Apache ServiceMix :: Bundles :: velocity (66): org.apache.velocity.context; version=1.7.0
            Apache ServiceMix :: Bundles :: velocity (66): org.apache.velocity; version=1.7.0
            Servlet 3.0 (132): javax.servlet; version=2.6.0
            Servlet 3.0 (132): javax.servlet.http; version=2.6.0
            Servlet 3.0 (132): javax.servlet; version=3.0.0
            Servlet 3.0 (132): javax.servlet.http; version=3.0.0
            Concurrent (216): EDU.oswego.cs.dl.util.concurrent; version=1.3.4
            

             

            I thought servicemix would automatically refresh a bundle if an optional dependency became available?

             

            Thanks,

            Dustin

            • 3. Re: NoClassDefFoundError even though package imported
              Dustin S. Newbie

              FYI, this is using equinox as the runtime, not felix.

              • 4. Re: NoClassDefFoundError even though package imported
                Freeman(Yue) Fang Master

                Hi,

                 

                No, the default behavior for installing single bundle isn't auto refresh, as the refresh package can cause chain-action,  likely if bundle A get refreshed, then all bundles transitively depend bundleA(import package from bundleA) will get refreshed also, this would be CPU heavy cost operation, and per OSGi spec, you should have chance to refresh manually after install a bunch of bundles, so that only one time CPU heavy cost operation to refresh all involved bundles.

                 

                However, you can put all related bundles into a feature, install a certain feature can overcome the problem you encounter now.

                 

                Freeman

                • 5. Re: NoClassDefFoundError even though package imported
                  Dustin S. Newbie

                  Thanks Freeman, this is helpful!