My earlier claims of success were overly optimistic. Just getting
everything to load into osgi was one hurdle, but getting jaxb running is a
completely different story.

With the configuration mentioned below,

g! lb | grep -i jax
   65|Active     |   30|jaxb-api (2.2.11)
   66|Active     |   30|Old JAXB Core (2.2.11)


attempting to instantiate a JAXBContext does not work,

  JAXBContext context = JAXBContext.newInstance(new Class[]
{com.nim.content.formats.folio.schema.FolioType.class});

(syntax modification as indicated in [1])

fails with a ClassCastException:


04.02.2015 07:32:50.136 *ERROR* [pool-6-thread-1-<main
queue>(incoming/file)] com.nim.ct.dam.ingest.jobs.ImportFileJobConsumer
Exception: java.lang.NullPointerException
java.lang.NullPointerException: null
        at 
javax.xml.bind.ContextFinder.handleClassCastException(ContextFinder.java:12
9)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:265)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:249)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:477)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:656)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:599)
        at 
com.nim.content.formats.folio.DefaultFolioReader.<init>(DefaultFolioReader.
java:45)


Then I tried to use the jaxb-osgi package. I could not even get this to
load in sling. These were the sling import warnings on the bundle on the
com.sun.xml.bind.jaxb-osgi bundle (jaxb-osgi-2.2.11.jar)



com.sun.org.apache.xml.internal.resolver -- Cannot be resolved but is not
required and overwritten by Boot Delegation
com.sun.org.apache.xml.internal.resolver.tools -- Cannot be resolved but
is not required and overwritten by Boot Delegation
com.sun.source.tree -- Cannot be resolved and overwritten by Boot
Delegation
com.sun.source.util -- Cannot be resolved and overwritten by Boot
Delegation
javax.xml.bind,version=2.2.12.b1401091041 -- Cannot be resolved but is not
required
javax.xml.bind.annotation,version=2.2.12.b1401091041 -- Cannot be resolved
but is not required
javax.xml.bind.annotation.adapters,version=2.2.12.b1401091041 -- Cannot be
resolved but is not required
javax.xml.bind.attachment,version=2.2.12.b1401091041 -- Cannot be resolved
but is not required
javax.xml.bind.helpers,version=2.2.12.b1401091041 -- Cannot be resolved
but is not required



I’m a bit at a loss what to try next.

-Bruce


[1] 
http://blog.kusandriadi.com/problem-using-jaxb-marshallingunmarshalling-wit
hin-osgi-container/


>Thanks for the hints Stephan. They got me going in the right direction.
>
>My problems went away after I added these to my launchpad¹s list.xml:
>
><bundle>
>  <groupId>javax.xml.bind</groupId>
>  <artifactId>jaxb-api</artifactId>
>  <version>2.2.11</version>
></bundle>
>               <bundle>
>  <groupId>com.sun.xml.bind</groupId>
>  <artifactId>jaxb-core</artifactId>
>  <version>2.2.11</version>
>               </bundle>
>
>I¹m not entirely sure what was causing the problem, but there seems to be
>some inconsistency in module naming in this area.
>
>
>With the above bundles specified, the felix console bundles now include:
>
>Old JAXB Core com.sun.xml.bind.jaxb-core 2.2.11 Active
>jaxb-api jaxb-api 2.2.11 Active
>
>
>Manually forcing these to load at launchpad start time satisfied the later
>bundle load-time dependencies.
>
>-Bruce
>
>
>>the packages javax.xml.bind.* are part of the java runtime (at least for
>>the newer JDKs 7 and up), but not exported by the OSGi system bundle by
>>default.
>>
>>if not done already please install the bundle
>>org.apache.sling:org.apache.sling.fragment.xml:1.0.2 and restart the
>>instance, this extends the list of exported packages of the java runtime
>>for the XML-related packages. but this package currently only exports
>>JAXB version 2.1.0, can you downgrade to this version? as a rule of thumb
>>you should always try to use the packages von the java runtime if they
>>are included in the version you use and install the appropriate fragment
>>bundle that extends the export list.
>>
>>packages starting with com.sun.xml are internal-only packages, are not
>>exported by the system bundle in general and should not be used.
>>
>>if you really have to update JAXB to a newer version than this can become
>>cumbersome, because those libraries tend to import packages like
>>com.sun.xml which are not exported and have dependencies which might be
>>difficult to resolve.
>>
>>stefan
>>
>>>
>>>I'm running into this error trying to use jaxb in a bundle:
>>>
>>>com.sun.xml.bind -- Cannot be resolved and overwritten by Boot
>>>Delegation
>>>com.sun.xml.bind.annotation -- Cannot be resolved and overwritten by
>>>Boot
>>>Delegation
>>>javax.xml.bind,version=[2.2,3) -- Cannot be resolved
>>>javax.xml.bind.annotation,version=[2.2,3) -- Cannot be resolved
>>>
>>>I assume I need to replace the standard jaxb-core and jaxb-api with the
>>>osgi
>>>variants (jaxb-osgi and jaxb-osgi-extra?), but I haven't found the magic
>>>incantation for the maven-bundle-plugin to get this to load in sling.
>>>
>>>What is the procedure for declaring jaxb as a bundle dependency in the
>>>pom.xml?
>>>
>>>-Bruce
>>
>
>
>
>

Reply via email to