java - Why can't JAXB find my jaxb.index when running inside Apache Felix? -


That's right, in the package, it should be indexing. However, when I call

  JAXBContext jc = JAXBContext.newInstance ("my.package.name");  

I have been told a JAXBException that

"My.package.name" does not include ObjectFactory.class or jaxb.index

Although it includes both.

What works, but what I want is not it

  JAXBContext jc = JAXBContext.newInstance (my package.name.SomeClass.class);  

This question appears on quite a few mailing lists and forums from various other people, but it seems that the answer is no.

I am running it on OpenJDK6, so I have got the source package and my debugger has been transferred to the library. It starts with the discovery of jaxb.properties, then looks for system properties and is unable to find either, it tries to make a default reference using com.sun.internal.xml.bind.v2.ContextFactory . In it, the exception is thrown within ( ContextFactor.createContext (string classloader, map) ), but I can not see what is happening because the source is not here.

ETA :

Looking at ContentFactory's source code, I found, this is probably a piece of code that fails to work with purpose:

  / ** * Find the jaxb.index file in the specific package and * * to search the absolute class loader class loader * * @ to load the absolute PKG package name * Load a list of items, empty if there is no * @ throw, IOException, then read any index file * _throws JAXBException Ruti is, if there are any errors in the index file / / private static List & lt; Class & gt; LoadIndexedClasses (string Pikeji, class loader Clasloder) throws IOException, JAXBException {final String resource = pkg.replace ( '.', '/') + "/jaxb.index"; Final input stream processing estestream = classloader.tterresource eststream (resource); If (resourceAsstream == tap) {return tap; }  

From my side, I'm guessing that this is going to do with the class loading mechanism of OSGi container that is running it. Unfortunately, I'm still a little bit from my depth here.

OK, it takes a lot of digging, but the answer is not surprising, and so far That's not too complicated:

JAXB can not find jaxb.index, because by default, the new difference (string) uses the current thread class loader (As returned by the thread) .getContextClassLoader () ). It does not work inside Felix, because OSGi bundles and frameworks have different class loaders of thread.

The solution is to obtain an appropriate class loader from anywhere and newInstance string, classloader). I got an appropriate class loader from a class of package containing jaxb.index , a sensible option for flexibility reasons might be ObjectFactory :

 < Code> Classloader cl = my.package.name.ObjectFactory.class.getClassLoader (); JAXBContext Jesse = JAXBContext.newInstance ("my.package.name", cl);  

You may also be able to find on the class loader that the bundle is using the example, but I did not understand how and above The solutions are safe.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -