1 2 Previous Next 16 Replies Latest reply on Dec 5, 2010 8:27 AM by ffang

    NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext

    concombremasqué

      Hi,

       

      Using FUSE ESB 4.2.0 with Sun JDK 1.6 update 18, I got following exception when trying to create a new JAXBContext (JAXBContext.newInstance(packageName)):

       

      15:08:02,249 | ERROR | Event Dispatcher | ExchangeActivator                | my.exchange.ExchangeActivator   42 | javax.xml.bind.JAXBException: Unable to create context

      - with linked exception:

      java.lang.NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String, java.lang.ClassLoader)

       

      And yes by looking to the jaxb-impl jar provided with servicemix there is no such createContext() method that takes these parameters, I totally agree. The problem is why I got this exception?

       

      It works fine using PAX Exam (with a platform like FUSE ESB: equinox 3.5.1, same servicemix features deployed etc...).

       

      I've tried to put servicemix jaxb jars into the endorsed folder but the exception is still there.

       

      Thanks.

      CM

        • 1. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
          concombremasqué

          Solved. (Classloading issue)

           

          CM

          • 2. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
            konrad.garlikowski

            Hey,

             

            currently I'm facing the same problem when trying to deploy some rest service using cxf and JAXB (servicemix 4.2.0). Could somebody explain how to overcome the class loading problems?

             

            Thanks in advance,

            Konrad.

            • 3. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
              michael.wengle

              We face the same problem with FUSE 4.2 and Java(TM) SE Runtime Environment (build 1.6.0_20-b02). We are NOT using CXF (Only Camel and ActiveMQ).

              • 4. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                davsclaus

                What OS are you using?

                 

                And did it work before? eg did you upgrade JDK or something, and then it stopped working?

                • 5. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                  michael.wengle

                  Thank you for the quick reply.

                   

                  I'm using Windows Vista but that is probably not crucial since I don't get the same error with all my bundles. Other bundles work successfully with JAXB and Camel on the same FUSE 4.2 installation.

                   

                  The problem occurs when I deploy the bundles that I attached to this reply. The attachment also contains a log file.

                   

                  This is not a blocking issue for me but this is an error I saw in the past from time to time and I would like to know how I can avoid it.

                   

                  Edit: The problem appears only on startup and not when I deploy the bundles on a running instance.

                   

                  Edited by: michael.wengle on Apr 20, 2010 11:53 AM

                  • 6. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext

                    How does one solve this classloading problem?

                    I get the same error when using the marshalling function of camel-jaxb:

                     

                    Caused by: javax.xml.bind.JAXBException: Unable to create context

                    - with linked exception:

                    java.lang.NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String, java.lang.ClassLoader)

                        at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)

                        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)

                        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)

                        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)

                        at org.apache.camel.converter.jaxb.JaxbDataFormat.createContext(JaxbDataFormat.java:242)

                        at org.apache.camel.converter.jaxb.JaxbDataFormat.getContext(JaxbDataFormat.java:183)

                        at org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:76)

                        ... 69 more

                    Caused by: java.lang.NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String, java.lang.ClassLoader)

                        at java.lang.Class.getMethod(Class.java:1605)

                        at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)

                        ... 75 more

                     

                    I decompiled the class in bundle Apache ServiceMix Specs :: JAXB API 2.1 (1.4.0) -> ContextFinder.java:

                     

                        if(className == null)

                                className = "com.sun.xml.bind.v2.ContextFactory";

                            spi = loadSpi(className, classLoader);

                            Method m = spi.getMethod("createContext", new Class[] {

                                java/lang/String, java/lang/ClassLoader, java/util/Map

                            });

                            return (JAXBContext)m.invoke(null, new Object[] {

                                contextPath, classLoader, properties

                            });

                            Throwable t;

                            t;

                            t = spi.getMethod("createContext", new Class[] {

                                java/lang/String, java/lang/ClassLoader

                            });

                            return (JAXBContext)t.invoke(null, new Object[] {

                                contextPath, classLoader

                            });

                            t;

                            throw new JAXBException("Unable to create context", t);

                     

                    If I check the bundle Apache ServiceMix Bundles: jaxb-impl-2.1.12 (2.1.12.1) -> ContextFactory for the specific method with arguments java/lang/String, java/lang/ClassLoader I can't find it since this is JAXB 1.0.

                     

                    Why didn't the first JAXB 2.0 method result in a success? I find this quite odd.

                        Method m = spi.getMethod("createContext", new Class[] {

                                java/lang/String, java/lang/ClassLoader, java/util/Map

                            });

                     

                    This thread/question is marked as answered but I can't find a helpful thing in here. Can someone push me in the right direction?

                    • 7. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                      gertv

                      L.S.,

                       

                      Could you attach a sample bundle or some instructions on how to reproduce this issue?  It looks like it's recurring now and then for people, so if we can get some extra input to get it fixed, that would be nice.

                       

                      Regards,

                       

                      Gert Vanthienen

                      • 8. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                        michael.wengle

                        I had the same exception when I wanted to load a Camel route from a XML file.

                         

                        This solved the problem for me: Add the imports that are defined in "Constants.JAXB_CONTEXT_PACKAGES" to the OSGi bundle:

                         

                        Bundle Plugin for Maven:

                         

                         

                        Edited by: michael.wengle on Dec 6, 2010 11:05 AM

                         

                        Edited by: michael.wengle on Dec 7, 2010 8:47 AM

                        • 9. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                          dustin_dustin.schultz

                          I keep seeing this error pop up and I solve it and then I forget how I solved it. It's definitely a classpath issue ... the bundle seeing the wrong jaxb api or impl.

                           

                          Right now, the way it occurs for me is on an OSGi service that's imported into another bundle that uses the client's classloader. If I switch the classloader to service-provider I don't see the error.

                          • 10. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                            dustin_dustin.schultz

                            Ok, with help from a coworker, the problem likely results from not being able to find a jaxb.index or ObjectFactory. You may have these but make sure that the OSGi classpath is seeing them.

                             

                            In ContextFactory:

                             

                            Method m = spiClass.getMethod("createContext",String.class,ClassLoader.class,Map.class);

                            context = m.invoke(null,contextPath,classLoader,properties);

                             

                            // Context will == null if you don't have a jaxb.index or ObjectFactory

                             

                            if(context==null) {

                            createContext method.

                                            Method m = spiClass.getMethod("createContext",String.class,ClassLoader.class);

                                            context = m.invoke(null,contextPath,classLoader);

                            }

                             

                            Then you get the NoSuchMethodException from the second call.

                            • 11. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                              dustin_dustin.schultz

                              More inspection on this shows that the jaxb-api used by FUSE has

                               

                              try {

                                         Method m = spi.getMethod("createContext", new Class[] { String.class, ClassLoader.class, Map.class });

                                         return (JAXBContext) m.invoke(null, new Object[] { contextPath, classLoader, properties });

                                     } catch (Throwable t) {

                                         // Ignored

                                     }

                               

                              Other implementations have

                               

                                          } catch (NoSuchMethodException e) {

                                              // it's not an error for the provider not to have this method.

                                          }

                               

                              The throwable swallows the real exception if an ObjectFactory or a jaxb.index is not found:

                               

                                          if( !(foundObjectFactory || foundJaxbIndex) ) {

                                              throw new JAXBException( Messages.BROKEN_CONTEXTPATH.format(pkg));

                                          }

                               

                              Edit: sources here:

                               

                              http://www.jarvana.com/jarvana/archive-details/org/apache/servicemix/specs/org.apache.servicemix.specs.jaxb-api-2.0/1.4.0/org.apache.servicemix.specs.jaxb-api-2.0-1.4.0-sources.jar

                               

                              Edited by: dustin on Jun 18, 2010 8:59 PM

                              • 12. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                                ffang

                                Hi,

                                 

                                FYI, SMX4-580[1] tracked this issue and already get fixed.

                                 

                                 

                                https://issues.apache.org/activemq/browse/SMX4-580

                                 

                                Freeman

                                • 13. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                                  sharma_arun_se1

                                  Hi,

                                   

                                  I hope somebody have solved this problem, as I can see there are number of posting for the problem but no real and satisfactory common solution to the problem.

                                   

                                  Let me discuss my issue:

                                   

                                  I have created jaxb bean as :

                                     

                                   

                                  In my routeBuilder.java Class, I have create route as :

                                   

                                       from(quartzUri)

                                        .to(DataextracterUri)

                                        .marshal(myjaxb)

                                        .to(ftpServerURI);

                                   

                                  Now for your concern, I verify you that my jaxb generated classes are in package: com.xyz.abc.xa.jaxb.generated. This include ObjectFactory.class. But there is nothing like jaxb.index inside it.

                                   

                                  Why classloader not picking up the class ObjectFactory, although it is there in com.xyz.abc.xa.jaxb.generated package.

                                   

                                   

                                  FYI: I am deploying my bundle using feature in ServiceMix 4.3--2.0

                                   

                                   

                                  Error Log:

                                   

                                  Caused by: javax.xml.bind.JAXBException: Unable to create context

                                  - with linked exception:

                                  http://java.lang.reflect.InvocationTargetException

                                  at javax.xml.bind.ContextFinder.find(ContextFinder.java:68)

                                  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)

                                  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)

                                  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)

                                  at com.vzb.ram.bind.ns.XmlPoJoUtil.toPoJo(XmlPoJoUtil.java:185)

                                  ... 54 more

                                  Caused by: java.lang.reflect.InvocationTargetException

                                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):1.6.0_18

                                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39):1.6.0_18

                                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25):1.6.0_18

                                  at java.lang.reflect.Method.invoke(Method.java:597):1.6.0_18

                                  at javax.xml.bind.ContextFinder.find(ContextFinder.java:63)

                                  ... 58 more

                                  Caused by: javax.xml.bind.JAXBException: "com.xyz.abc.xa.jaxb.generated" doesnt contain ObjectFactory.class or jaxb.index

                                  at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)

                                  ... 63 more

                                   

                                   

                                  Thank you,

                                   

                                  Arun Kumar (sharma_arun_se)

                                   

                                  Edited by: sharma_arun_se on Nov 16, 2010 4:02 PM

                                  • 14. Re: NoSuchMethodException: com.sun.xml.bind.v2.ContextFactory.createContext
                                    sharma_arun_se1

                                    Hi All,

                                     

                                    I have found alternative solution of my problem. If anybody face same kind of problem, I will be more than happy to discuss the solution.

                                     

                                     

                                    Regards,

                                     

                                    Arun Kumar (sharma_arun_se)

                                     

                                    Expert SOA (Fuse ESB, Camel, ActiveMQ, OSGi) and RESTful Solution Architect, Open Source Contributor.

                                    linkedin: http://in.linkedin.com/in/aronkumar

                                    twitter: https://twitter.com/#!/SharmaArunKumar

                                    blog: http://techiesweek.blogspot.com/

                                    1 2 Previous Next