4 Replies Latest reply on Apr 21, 2011 5:10 AM by Ben Clark

    Loader constraint violation

    Ben Clark Newbie

      Hello everyone,

       

      I know this problem was discussed on others topics but I'm still trapped..

       

      I'm doing an Enrich pattern with Camel with the following code:

       

      ...

      enrich("direct:hello", new MyStrategy()).

      ...

       

      MyStrategy is my class which implements org.apache.camel.processor.aggregate.AggregationStrategy

      But on the deployment I have the following error:

       

      Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.camel.model.RouteDefinition.enrich(Ljava/lang/String;Lorg/apache/camel/processor/aggregate/AggregationStrategy;)Lorg/apache/camel/model/ProcessorDefinition;" the class loader (instance of org/apache/xbean/classloader/JarFileClassLoader) of the current class, org/xxx/xxx/msl/MyRouteBuilder, and the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoaderJava5) for resolved class, org/apache/camel/model/RouteDefinition, have different Class objects for the type org/apache/camel/processor/aggregate/AggregationStrategy used in the signature

       

      To resume, org.xxx.xxx.msl.MyRouteBuilder invokes AggregationStrategy with JarFileClassLoader and org.apache.camel.model.ProcessorDefinition invokes AggregationStrategy with ModuleClassLoader.

       

      I found this  http://servicemix.apache.org/classloaders.html on the Apache documentation, but I'm a little bit confused...

      In my pom.xml, the dependencies which contains the AggregationStrategy class is:

       

      <dependency>

            <groupId>org.apache.camel</groupId>

            <artifactId>camel-core</artifactId>

            <version>2.7.0</version><!-- en 2.7.0 sur ma version 1.0 -->

          </dependency>

       

      Am I supposed to change this dependencies ? How can I avoid this exception :/ ?

       

      Thx in advance

        • 1. Re: Loader constraint violation
          Freeman(Yue) Fang Master

          Hi,

           

          Could you elaborate your application?

           

          A few question like

          1. is your application a pure camel bundle or a use JBI servicemix-camel component?

          2. if it use JBI servicemix-camel component,  you you use OSGi package or JBI package?

          3. in your bundle do you embed any camel related jars?

           

          Freeman

          • 2. Re: Loader constraint violation
            Ben Clark Newbie

            1. It's a servicemix component with a SA project containing multiple SU which one of them is a Camel SU.

             

            2. And I'm just using the JBI style

             

            3. In my project-sa.zip, there is a camel-su.zip which contains in the lib directory a camel-core.jar

            • 3. Re: Loader constraint violation
              Freeman(Yue) Fang Master

              Hi,

               

              3. In my project-sa.zip, there is a camel-su.zip which contains in the lib directory a camel-core.jar

               

              I think this is the problem, as OSGi container already provide this camel-core.jar, that's why you saw classloader conflict issue, one class loaded from the OSGi container camel-core, one from your SU.

              This is a trouble when you use JBI package.

              You need do a little tricky like

              1. mark camel-core dependency in your SU pom.xml as provided scope like

               

              into your SU bean.xml, this can make your SU refer the camel-core bundle jar from osgi container, more details from

               

               

              I encourage you should use OSGi packaging but not old JBI packaging as now you're working with a OSGi container, with OSGi packaging you needn't package 3rd  libs into your own SA, all are shared from the bundles installed in the container.

               

              http://servicemix.apache.org/classloaders.html

              Freeman

               

              Edited by: ffang on Apr 20, 2011 9:25 AM

              • 4. Re: Loader constraint violation
                Ben Clark Newbie

                Indeed, I passed my project under the OSGI way and it works perfectly

                 

                Thanks again