Hi list,

I seem to have a rather specific problem with using JAXB inside the Felix 
framework.

Here's my situation:

- Felix Framework 2.0.0
- Java 1.6.0_18
- JAXB included in the JDK (2.1.10 according to xjc -version)

I want to use JAXB in a bundle I am developing. 

Now, I first stumbled into the typical error everybody has, where you do 
not set the classloader and JAXB is missing its ObjectFactory.class.
The solution to this issue is rather straight forward, as you have to 
provide the correct classloader to JAXB. So what I do is the following:

exchange:

JAXBContext jc = JAXBContext.newInstance(packageName);

with

JAXBContext jc = JAXBContext.newInstance(packageName, 
ObjectFactory.class.getClassLoader());

Usually that seems to be the moment where everybody else gets lucky, and 
has their problem solved. Unfortunately I did not get that lucky. :-/
While this helps to get over the aforementioned problem, I am now stuck 
with something that nobody else so far seems to have encountered. During 
unmarshalling I get an CNFE for a part of the JAXB implementation:

java.lang.NoClassDefFoundError: 
com/sun/xml/internal/bind/DatatypeConverterImpl
        at 
com.orga.my.package.State_JaxbXducedAccessor_ordinal.parse(TransducedAccessor_field_Integer.java:57)
        at 
com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:191)
        at 
com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:470)
        at 
com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:448)
        at 
com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:79)
        at 
com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
        at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
        at 
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
        at 
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
        at 
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
        at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
        at 
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at 
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
        at 
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at 
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at 
com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:200)
        at 
com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:173)
        at 
javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
        at 
javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
        at 
com.orga.my.package.MyJaxbClient.unmarshal(MyJaxbClient.java:312)
        at 
com.orga.my.package.MyJaxbClient.reconfigure(MyJaxbClient.java:164)
        at 
com.orga.my.package.MyJaxbClient.initialize(MyJaxbClient.java:118)
        at 
com.orga.my.package.internal.CamBundleActivator.startInternal(CamBundleActivator.java:152)
        at 
com.orga.my.package.util.osgi.BaseBundleActivator.start(BaseBundleActivator.java:88)
        at 
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:667)
        at 
org.apache.felix.framework.Felix.activateBundle(Felix.java:1699)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1621)
        at 
org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1076)
        at 
org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: 
com.sun.xml.internal.bind.DatatypeConverterImpl
        at 
org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:726)
        at 
org.apache.felix.framework.ModuleImpl.access$100(ModuleImpl.java:60)
        at 
org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1631)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        ... 32 more

I tried to fix this by using the alternate solution to the "newInstance 
with ClassLoader" call, i.e. by setting the Thread's ContextClassloader to 
the one that is used to load my ObjectFactory class. But this gives me the 
same result.

Now, what I did next, was to fiddle around with the felix's classloader 
configuration inside the config.properties. Adding "sun.*, com.sun.*" to 
the system.packages.extra did not change anything. BUT, adding those to 
the boot delegation property, e.g. 

org.osgi.framework.bootdelegation=sun.*,com.sun.*

Did indeed fix the issue. 

What really puzzles me, is that according to the stack trace I get, 
several subpackages of com.sun.xml.internal.bind are available without the 
change of the boot delegation property. But DatetypeConverter which 
resides directly in that package is not visible to my bundle's CL without 
the aforementioned change to the configuration.

Does anybody have an idea what actually might be going wrong?
Is there a way for me to fix this without changing the boot delegation 
property?

Thanks for any insights!

bye, Michael



The information included in this e-mail and any files transmitted with it is 
strictly confidential and may be privileged or otherwise protected from 
disclosure. If you are not the intended recipient, please notify the sender 
immediately by e-mail and delete this e-mail as well as any attachment from 
your system. If you are not the intended recipient you are not authorized to 
use and/or copy this message and/or attachment and/or disclose the contents to 
any other person.

Reply via email to