You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Tim Moloney <t....@verizon.net> on 2007/03/18 23:46:32 UTC

Has anyone used JAXB within Felix?

I'm trying to use JAXB within a bundle that I'm writing but I'm not 
having much luck.

I can compile and start my bundle (after I load the jaxb-libs, jax-impl, 
relaxngDatatype, and xsdlib bundles I wrapped).  However, I get a 
runtime error ("my.domain.package" doesnt contain ObjectFactory.class or 
jaxb.index) when I try to get a JAXB context.

ObjectFactory is in my.domain.package (it's actually generated by 
hyperjaxb2) and I've exported my.domain.package.* from my bundle, but 
com.sun.xml.internal.bind.v2.ContextFactory.createContext() can't seem 
to find it.

Any thoughts on what else I may need to do?

Thanks,
  Tim


Re: Has anyone used JAXB within Felix?

Posted by Rob Walker <ro...@ascert.com>.
>
> Sorry.  I meant to respond to you previous post.  So far, I've been 
> unable to duplicate what you've done by putting the JAXB libs in the 
> same bundle as my schema generated classes.  Although this isn't the 
> best solution, I wanted to have some small success by duplicating your 
> solution.  What I'd really like to see is a solution that allows JAXB 
> to be bundled and added to the Felix commons.
>
> I do appreciate your response.  It tells me that I'm not fighting a 
> losing battle.  I just need to learn more about how imports, exports, 
> and class loading work in OSGi.
>
No worries - happy to keep you positive!

When I glanced back at our old code, I actually found very few JAXB libs 
that it actually seemed to need at runtime (i.e. that we'd built into 
bundles). I think the trick is getting your generated classes into 
something like a schema JAR that has all the right imports and exports.

Depending on your SAX parser, you might also need the old 
"setContextClassloader" fix, which is often needed because some XML/SAX 
classes find the classloader using the thread's context classloader e.g.

        
Thread.currentThread().setContextClassLoader(VtFormatLoader.class.getClassLoader());

Unfortunately, this may need to go anywhere you create a new thread - 
our app has a single place where we create threads, so we localised it 
in there.

-- Rob



Re: Has anyone used JAXB within Felix?

Posted by Tim Moloney <t....@verizon.net>.
Rob Walker wrote:
> I can answer part 2
>> - If OSGi is using custom class loaders and JAXB is using different 
>> class loaders, will JAXB ever work in OSGi?
>>
> Yes it will and it does - we did it some time ago and it worked fine 
> (as per my earlier post)
>
> In fact, I seem now to recall that JAX-B only actually has a very 
> small set of runtime classes - from memory mostly it's a build-time, 
> generation tool. The Java classes it creates are mostly standalone 
> with needs largely on things like XML parsers. I seem to remember some 
> namespace handling and RI classes, and that was about it.  So it's 
> mostly about bundling your generated classes in a correct with all the 
> necessary imports and exports.
>
> -- Rob

Sorry.  I meant to respond to you previous post.  So far, I've been 
unable to duplicate what you've done by putting the JAXB libs in the 
same bundle as my schema generated classes.  Although this isn't the 
best solution, I wanted to have some small success by duplicating your 
solution.  What I'd really like to see is a solution that allows JAXB to 
be bundled and added to the Felix commons.

I do appreciate your response.  It tells me that I'm not fighting a 
losing battle.  I just need to learn more about how imports, exports, 
and class loading work in OSGi.

Tim


Re: Has anyone used JAXB within Felix?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
GERODOLLE Anne RD-MAPS-GRE wrote:
> Hi,
>
> I've had similar problem, and solved it by using jaxb methods that accept a classloader as argument.
>
> Ex : JAXBContext.newInstance(somepackage, myclassloader) will work, provided myclassloader is able to load the generated class.
>
> But if you call JAXBContext.newInstance(somepackage) it uses the Thread.getContextClassLoader method and it won't work in OSGi.
>
> You don't have to use a wild-carded dynamic import (and it even does not work).
>
> However, I have not tested with felix, only with Oscar. I had also to provide the package explicitely because the getPackage method would return null with classes loaded by the Oscar class loader.
>   

Felix now defines a Package object for classes its loads...

-> richard

> Regards,
>
> Anne
> -----Message d'origine-----
> De : Rob Walker [mailto:robw@ascert.com] 
> Envoyé : mercredi 21 mars 2007 10:09
> À : felix-dev@incubator.apache.org
> Objet : Re: Has anyone used JAXB within Felix?
>
> I can answer part 2
>   
>> - If OSGi is using custom class loaders and JAXB is using different 
>> class loaders, will JAXB ever work in OSGi?
>>
>>     
> Yes it will and it does - we did it some time ago and it worked fine (as per my earlier post)
>
> In fact, I seem now to recall that JAX-B only actually has a very small set of runtime classes - from memory mostly it's a build-time, generation tool. The Java classes it creates are mostly standalone with needs largely on things like XML parsers. I seem to remember some namespace handling and RI classes, and that was about it.  So it's mostly about bundling your generated classes in a correct with all the necessary imports and exports.
>
> -- Rob
>   
>> Thanks,
>>  Tim
>>
>> Felix Meschberger wrote:
>>     
>>> Hi,
>>>
>>> On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
>>>       
>>>> I've not worked with class loaders before.  How do I know which 
>>>> class loaders are being used?  Where can I read more about them?
>>>>         
>>> Well, you "work with class loaders" all the time, but you don't know.
>>> In fact, the whole OSGi Module spec is centered around Java 
>>> ClassLoading. :-)
>>>
>>> You will find numerous documentation on class loading on the net, e.g.
>>> http://www.javalobby.org/java/forums/t18345.html
>>> http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html
>>>
>>> Point here is, that two Class instances loaded by different 
>>> ClassLoader instances are not the same even thought their byte code 
>>> might be exactly the same. And this is one of the tricky things 
>>> regarding class loaders because this situation is somewhat difficult 
>>> to trace.
>>>
>>>       
>>>> I'm not sure that the source for JAXB is available but I'll look.
>>>>
>>>> Thanks for the suggestions.  :)
>>>>         
>>> You are welcome.
>>>
>>> Regards
>>> Felix
>>>
>>>       
>
>   

Re: Has anyone used JAXB within Felix?

Posted by Tim Moloney <t....@verizon.net>.
Here is an email, sent to me off-list, that has other solutions.

I confirmed that the first solution works but I didn't try the second 
since that creates a custom JAXB bundle that wouldn't work in the Felix 
Commons.

Thanks again for everyone's help on this.

Tim


zze-SEYVOZ Stephane RD-MAPS-GRE wrote:
>
> Hi there, I've actually been working on XFire integration in Felix for 
> a project at my university, and had an interest for it in the context 
> of my internship at France Telecom R&D.
>
> Here is what I would answer to the problem as it was described (quote 
> below)
>
> There are 2 different solutions (the first one I drop like this if you 
> don't want to know the details, the second one I haven't used by 
> contains the explanation of the problem) :
>
> 1) write this method call :
> "Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());" 
> in your application bundle (not the one containing JAXB) just before 
> the method call of your application that calls internally JAXB.
>
> This will force the current thread to use the classloader of your 
> application bundle, that (I hope) contains an implementation of a 
> factory or parser that JAXB wants to use. In fact, each bundle being 
> run in a different classloader as you know, JAXB tries to find a 
> parser or factory it hasn't got (this allows you to design the one you 
> want) whereas you surely have an implementation of it in your 
> application bundle. In the case it doesn't find it (through a config 
> file or searching in the current class loader with something like a 
> Class.forName), it falls back on the implementation of the people who 
> wrote the API, for instance as it falls back on com.sun … it's Sun 
> (well yes you knew it ^^)). And in your case it can't even find Sun's 
> one too. The command I gave you may resolve the problem as all the 
> loaded classes of both bundles will then be in the same classloader 
> (whereas it's not the same with the normal behavior of bundles in 
> Felix : one separated Thread per bundle).
>
> When you're not in Felix, there's surely no problem because the class 
> specified by the config file or that is in the JVM can be easily found 
> as it's loaded in the unique classloader running your application.
>
> 2) To resolve the same problem, you can export the implementation 
> class of the factory or parser you use in your application bundle A, 
> and import it in JAXB B. But be aware of the package dependendencies 
> of this class, as you also will have to export and import them, for 
> them to be accessible. I haven't tried this thing but it could work, 
> just try not to make the serpent bite its own tail.
>
> Seyvoz Stephane
>
> PS : I don't know how to be quoted on the forum/mailing list in order 
> to make everyone see the solution, as my master of internship directly 
> passed me the mails below. Feel free to do what you want with this mail :)
>


Re: Has anyone used JAXB within Felix?

Posted by Tim Moloney <t....@verizon.net>.
Thanks.  That did it.  :)


GERODOLLE Anne RD-MAPS-GRE wrote:
> Hi,
>
> I've had similar problem, and solved it by using jaxb methods that accept a classloader as argument.
>
> Ex : JAXBContext.newInstance(somepackage, myclassloader) will work, provided myclassloader is able to load the generated class.
>
> But if you call JAXBContext.newInstance(somepackage) it uses the Thread.getContextClassLoader method and it won't work in OSGi.
>
> You don't have to use a wild-carded dynamic import (and it even does not work).
>
> However, I have not tested with felix, only with Oscar. I had also to provide the package explicitely because the getPackage method would return null with classes loaded by the Oscar class loader.
>
> Regards,
>
> Anne
> -----Message d'origine-----
> De : Rob Walker [mailto:robw@ascert.com] 
> Envoyé : mercredi 21 mars 2007 10:09
> À : felix-dev@incubator.apache.org
> Objet : Re: Has anyone used JAXB within Felix?
>
> I can answer part 2
>   
>> - If OSGi is using custom class loaders and JAXB is using different 
>> class loaders, will JAXB ever work in OSGi?
>>
>>     
> Yes it will and it does - we did it some time ago and it worked fine (as per my earlier post)
>
> In fact, I seem now to recall that JAX-B only actually has a very small set of runtime classes - from memory mostly it's a build-time, generation tool. The Java classes it creates are mostly standalone with needs largely on things like XML parsers. I seem to remember some namespace handling and RI classes, and that was about it.  So it's mostly about bundling your generated classes in a correct with all the necessary imports and exports.
>
> -- Rob
>   
>> Thanks,
>>  Tim
>>
>> Felix Meschberger wrote:
>>     
>>> Hi,
>>>
>>> On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
>>>       
>>>> I've not worked with class loaders before.  How do I know which 
>>>> class loaders are being used?  Where can I read more about them?
>>>>         
>>> Well, you "work with class loaders" all the time, but you don't know.
>>> In fact, the whole OSGi Module spec is centered around Java 
>>> ClassLoading. :-)
>>>
>>> You will find numerous documentation on class loading on the net, e.g.
>>> http://www.javalobby.org/java/forums/t18345.html
>>> http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html
>>>
>>> Point here is, that two Class instances loaded by different 
>>> ClassLoader instances are not the same even thought their byte code 
>>> might be exactly the same. And this is one of the tricky things 
>>> regarding class loaders because this situation is somewhat difficult 
>>> to trace.
>>>
>>>       
>>>> I'm not sure that the source for JAXB is available but I'll look.
>>>>
>>>> Thanks for the suggestions.  :)
>>>>         
>>> You are welcome.
>>>
>>> Regards
>>> Felix
>>>
>>>       
>
>   


RE: Has anyone used JAXB within Felix?

Posted by GERODOLLE Anne RD-MAPS-GRE <an...@orange-ftgroup.com>.
Hi,

I've had similar problem, and solved it by using jaxb methods that accept a classloader as argument.

Ex : JAXBContext.newInstance(somepackage, myclassloader) will work, provided myclassloader is able to load the generated class.

But if you call JAXBContext.newInstance(somepackage) it uses the Thread.getContextClassLoader method and it won't work in OSGi.

You don't have to use a wild-carded dynamic import (and it even does not work).

However, I have not tested with felix, only with Oscar. I had also to provide the package explicitely because the getPackage method would return null with classes loaded by the Oscar class loader.

Regards,

Anne
-----Message d'origine-----
De : Rob Walker [mailto:robw@ascert.com] 
Envoyé : mercredi 21 mars 2007 10:09
À : felix-dev@incubator.apache.org
Objet : Re: Has anyone used JAXB within Felix?

I can answer part 2
> - If OSGi is using custom class loaders and JAXB is using different 
> class loaders, will JAXB ever work in OSGi?
>
Yes it will and it does - we did it some time ago and it worked fine (as per my earlier post)

In fact, I seem now to recall that JAX-B only actually has a very small set of runtime classes - from memory mostly it's a build-time, generation tool. The Java classes it creates are mostly standalone with needs largely on things like XML parsers. I seem to remember some namespace handling and RI classes, and that was about it.  So it's mostly about bundling your generated classes in a correct with all the necessary imports and exports.

-- Rob
> Thanks,
>  Tim
>
> Felix Meschberger wrote:
>> Hi,
>>
>> On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
>>> I've not worked with class loaders before.  How do I know which 
>>> class loaders are being used?  Where can I read more about them?
>>
>> Well, you "work with class loaders" all the time, but you don't know.
>> In fact, the whole OSGi Module spec is centered around Java 
>> ClassLoading. :-)
>>
>> You will find numerous documentation on class loading on the net, e.g.
>> http://www.javalobby.org/java/forums/t18345.html
>> http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html
>>
>> Point here is, that two Class instances loaded by different 
>> ClassLoader instances are not the same even thought their byte code 
>> might be exactly the same. And this is one of the tricky things 
>> regarding class loaders because this situation is somewhat difficult 
>> to trace.
>>
>>> I'm not sure that the source for JAXB is available but I'll look.
>>>
>>> Thanks for the suggestions.  :)
>>
>> You are welcome.
>>
>> Regards
>> Felix
>>
>

-- 


Ascert - Taking systems to the Edge
robw@ascert.com
+44 (0)20 7488 3470
www.ascert.com


Re: Has anyone used JAXB within Felix?

Posted by Rob Walker <ro...@ascert.com>.
I can answer part 2
> - If OSGi is using custom class loaders and JAXB is using different 
> class loaders, will JAXB ever work in OSGi?
>
Yes it will and it does - we did it some time ago and it worked fine (as 
per my earlier post)

In fact, I seem now to recall that JAX-B only actually has a very small 
set of runtime classes - from memory mostly it's a build-time, 
generation tool. The Java classes it creates are mostly standalone with 
needs largely on things like XML parsers. I seem to remember some 
namespace handling and RI classes, and that was about it.  So it's 
mostly about bundling your generated classes in a correct with all the 
necessary imports and exports.

-- Rob
> Thanks,
>  Tim
>
> Felix Meschberger wrote:
>> Hi,
>>
>> On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
>>> I've not worked with class loaders before.  How do I know which class
>>> loaders are being used?  Where can I read more about them?
>>
>> Well, you "work with class loaders" all the time, but you don't know.
>> In fact, the whole OSGi Module spec is centered around Java
>> ClassLoading. :-)
>>
>> You will find numerous documentation on class loading on the net, e.g.
>> http://www.javalobby.org/java/forums/t18345.html
>> http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html
>>
>> Point here is, that two Class instances loaded by different
>> ClassLoader instances are not the same even thought their byte code
>> might be exactly the same. And this is one of the tricky things
>> regarding class loaders because this situation is somewhat difficult
>> to trace.
>>
>>> I'm not sure that the source for JAXB is available but I'll look.
>>>
>>> Thanks for the suggestions.  :)
>>
>> You are welcome.
>>
>> Regards
>> Felix
>>
>

-- 


Ascert - Taking systems to the Edge
robw@ascert.com
+44 (0)20 7488 3470
www.ascert.com


Re: Has anyone used JAXB within Felix?

Posted by Tim Moloney <t....@verizon.net>.
Felix Meschberger wrote:
> On 3/21/07, Tim Moloney <t....@verizon.net> wrote:
>> - How do I determine which class loaders are loading which classes?
>
> Theres is no API to get the classes loaded by a certain class loader,
> but you can (of course) call Class.getClassLoader() to get the loader
> of the class. E.g. someObject.getClass().getClassLoader().
>
>> - If OSGi is using custom class loaders and JAXB is using different
>> class loaders, will JAXB ever work in OSGi?
>
> They are not necessairily different. The problem ist that JAXB is
> probably using some mechanism to find a class loader to use to refer
> to mappings. I am not familiar how this is actually done (never worked
> with JAXB) but generally there is some API to tweak the class loader
> loader used. It might be some parameter, some environment setting, the
> current thread's context class loader or even the loader of the
> factory class itself...
>
> You might want to also read the XML Parser Service Specification in
> the OSGi compendium. This even has a section "702.6 Adapting a JAXP
> Parser to OSGi". This might provide more hints.
>
> Regards
> Felix
>

Looks like more learning for me.  :)

Thanks again for your help.

Tim


Re: Has anyone used JAXB within Felix?

Posted by Felix Meschberger <Fe...@day.com>.
On 3/21/07, Tim Moloney <t....@verizon.net> wrote:
> - How do I determine which class loaders are loading which classes?

Theres is no API to get the classes loaded by a certain class loader,
but you can (of course) call Class.getClassLoader() to get the loader
of the class. E.g. someObject.getClass().getClassLoader().

> - If OSGi is using custom class loaders and JAXB is using different
> class loaders, will JAXB ever work in OSGi?

They are not necessairily different. The problem ist that JAXB is
probably using some mechanism to find a class loader to use to refer
to mappings. I am not familiar how this is actually done (never worked
with JAXB) but generally there is some API to tweak the class loader
loader used. It might be some parameter, some environment setting, the
current thread's context class loader or even the loader of the
factory class itself...

You might want to also read the XML Parser Service Specification in
the OSGi compendium. This even has a section "702.6 Adapting a JAXP
Parser to OSGi". This might provide more hints.

Regards
Felix

Re: Has anyone used JAXB within Felix?

Posted by Tim Moloney <t....@verizon.net>.
Good links on class loaders.  I can't say that I understood everything, 
but I think that I at least understand the bigger concepts.  I can also 
see why OSGi would have custom class loaders.

Now my questions are:
- How do I determine which class loaders are loading which classes?
- If OSGi is using custom class loaders and JAXB is using different 
class loaders, will JAXB ever work in OSGi?

Thanks,
  Tim

Felix Meschberger wrote:
> Hi,
>
> On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
>> I've not worked with class loaders before.  How do I know which class
>> loaders are being used?  Where can I read more about them?
>
> Well, you "work with class loaders" all the time, but you don't know.
> In fact, the whole OSGi Module spec is centered around Java
> ClassLoading. :-)
>
> You will find numerous documentation on class loading on the net, e.g.
> http://www.javalobby.org/java/forums/t18345.html
> http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html
>
> Point here is, that two Class instances loaded by different
> ClassLoader instances are not the same even thought their byte code
> might be exactly the same. And this is one of the tricky things
> regarding class loaders because this situation is somewhat difficult
> to trace.
>
>> I'm not sure that the source for JAXB is available but I'll look.
>>
>> Thanks for the suggestions.  :)
>
> You are welcome.
>
> Regards
> Felix
>


Re: Has anyone used JAXB within Felix?

Posted by Felix Meschberger <Fe...@day.com>.
Hi,

On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
> I've not worked with class loaders before.  How do I know which class
> loaders are being used?  Where can I read more about them?

Well, you "work with class loaders" all the time, but you don't know.
In fact, the whole OSGi Module spec is centered around Java
ClassLoading. :-)

You will find numerous documentation on class loading on the net, e.g.
http://www.javalobby.org/java/forums/t18345.html
http://www.onjava.com/pub/a/onjava/2005/01/26/classloading.html

Point here is, that two Class instances loaded by different
ClassLoader instances are not the same even thought their byte code
might be exactly the same. And this is one of the tricky things
regarding class loaders because this situation is somewhat difficult
to trace.

> I'm not sure that the source for JAXB is available but I'll look.
>
> Thanks for the suggestions.  :)

You are welcome.

Regards
Felix

Re: Has anyone used JAXB within Felix?

Posted by Rob Walker <ro...@ascert.com>.
I haven't used it with Felix - but used JAX-B fine under Oscar a few 
years back.

I seem to remember I found the easiest way to make it work was to 
package a "schema JAR" bundle which contained my schema, the generated 
classes, and the JAXB libs as inner JARs.

We use mangen, so the manifest imports/exports were created 
automatically for me. The result came out like this:

    Import-Package: javax.xml.parsers, javax.xml.transform, javax.xml.tran
     sform.dom, javax.xml.transform.sax, javax.xml.transform.stream, org.h
     ibernate, org.hibernate.cfg, org.w3c.dom, org.xml.sax, org.xml.sax.ex
     t, org.xml.sax.helpers

    Export-Package: com.ascert.vdrive.schema.drvdesc, com.ascert.vdrive.sc
     hema.drvdesc.impl, com.ascert.vdrive.schema.model, com.ascert.vdrive.
     schema.model.impl, com.sun.msv.datatype, com.sun.msv.datatype.xsd, co
     m.sun.msv.grammar, com.sun.xml.bind.util, javax.xml.bind, javax.xml.n
     amespace, org.relaxng.datatype


(this is quite an old one, and I think we were using HyperJAXB in this case)


Because JAXB libs are inside the bundle, I don't think they ended up 
needed exporting - just the schema classes generated.



-- Rob

Tim Moloney wrote:
> Felix Meschberger wrote:
>> Hi,
>>
>> On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
>>> to jaxb-impl's pom.xml file and verified that it appeared in the
>>> manifest.  I still get the same runtime error message.
>>
>> ok
>>
>>> Does this mean that reflection doesn't work in OSGi?
>>
>> No, reflection works (and I also depend in it :-) ).
>>
>> There might be other problems: For example, jaxb expecting the class
>> to implement a specific interface or the class not being public.
>>
>> Re Interface: This is a tricky issue. If the jaxb-impl and your
>> provider bundle do not use the same interface class instance because
>> it has been loaded from different class loaders, jaxb-impl will not
>> accept your class.
>
> I've not worked with class loaders before.  How do I know which class 
> loaders are being used?  Where can I read more about them?
>
>> After all, this is just wild guessing. What I would do in this
>> situation is to look at the source code of the method, which threw the
>> exception and try to find out, what makes jaxb this unhappy.
>>
>> Regards
>> Felix
>
> I'm not sure that the source for JAXB is available but I'll look.
>
> Thanks for the suggestions.  :)
>
> Tim
>

-- 


Ascert - Taking systems to the Edge
robw@ascert.com
+44 (0)20 7488 3470
www.ascert.com


Re: Has anyone used JAXB within Felix?

Posted by Tim Moloney <t....@verizon.net>.
Felix Meschberger wrote:
> Hi,
>
> On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
>> to jaxb-impl's pom.xml file and verified that it appeared in the
>> manifest.  I still get the same runtime error message.
>
> ok
>
>> Does this mean that reflection doesn't work in OSGi?
>
> No, reflection works (and I also depend in it :-) ).
>
> There might be other problems: For example, jaxb expecting the class
> to implement a specific interface or the class not being public.
>
> Re Interface: This is a tricky issue. If the jaxb-impl and your
> provider bundle do not use the same interface class instance because
> it has been loaded from different class loaders, jaxb-impl will not
> accept your class.

I've not worked with class loaders before.  How do I know which class 
loaders are being used?  Where can I read more about them?

> After all, this is just wild guessing. What I would do in this
> situation is to look at the source code of the method, which threw the
> exception and try to find out, what makes jaxb this unhappy.
>
> Regards
> Felix

I'm not sure that the source for JAXB is available but I'll look.

Thanks for the suggestions.  :)

Tim


Re: Has anyone used JAXB within Felix?

Posted by Felix Meschberger <Fe...@day.com>.
Hi,

On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
> to jaxb-impl's pom.xml file and verified that it appeared in the
> manifest.  I still get the same runtime error message.

ok

> Does this mean that reflection doesn't work in OSGi?

No, reflection works (and I also depend in it :-) ).

There might be other problems: For example, jaxb expecting the class
to implement a specific interface or the class not being public.

Re Interface: This is a tricky issue. If the jaxb-impl and your
provider bundle do not use the same interface class instance because
it has been loaded from different class loaders, jaxb-impl will not
accept your class.

After all, this is just wild guessing. What I would do in this
situation is to look at the source code of the method, which threw the
exception and try to find out, what makes jaxb this unhappy.

Regards
Felix

Re: Has anyone used JAXB within Felix?

Posted by Tim Moloney <t....@verizon.net>.
I was already exporting my.domain.package.* from my bundle.  jaxb-impl 
contains ContextFactory so I added

  <DynamicImport-Package>*</DynamicImport-Package>

to jaxb-impl's pom.xml file and verified that it appeared in the 
manifest.  I still get the same runtime error message.

Does this mean that reflection doesn't work in OSGi?

Tim


Felix Meschberger wrote:
> Hi Tim,
>
> This sounds very much as there is a classloading issue: It seems that a
> com.sun class - is this one in the JDK rt.jar ? - is trying to load a 
> class
> from a bundle. This however will never work.
>
> If the com.sun class is in any of the jaxb bundles, it might help to 
> declare
> a "global" dynamic import in the respective jaxb bundle manifest:
>
>     DynamicImport-Package: *
>
> Problem is, that two things must be true for a bundle to see another
> bundle's class: The class must be exported by the provider and must be
> imported by the consumer.
>
> Hope this helps
>
> Regards
> Felix
>
> On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
>>
>> Tim Moloney wrote:
>> > I'm trying to use JAXB within a bundle that I'm writing but I'm not
>> > having much luck.
>> >
>> > I can compile and start my bundle (after I load the jaxb-libs,
>> > jax-impl, relaxngDatatype, and xsdlib bundles I wrapped).  However, I
>> > get a runtime error ("my.domain.package" doesnt contain
>> > ObjectFactory.class or jaxb.index) when I try to get a JAXB context.
>> >
>> > ObjectFactory is in my.domain.package (it's actually generated by
>> > hyperjaxb2) and I've exported my.domain.package.* from my bundle, but
>> > com.sun.xml.internal.bind.v2.ContextFactory.createContext() can't seem
>> > to find it.
>> >
>> > Any thoughts on what else I may need to do?
>> >
>> > Thanks,
>> >  Tim
>>
>> I forgot to mention that JAXB works outside Felix as expected.
>>
>> Tim


Re: Has anyone used JAXB within Felix?

Posted by Felix Meschberger <Fe...@day.com>.
Hi Tim,

This sounds very much as there is a classloading issue: It seems that a
com.sun class - is this one in the JDK rt.jar ? - is trying to load a class
from a bundle. This however will never work.

If the com.sun class is in any of the jaxb bundles, it might help to declare
a "global" dynamic import in the respective jaxb bundle manifest:

     DynamicImport-Package: *

Problem is, that two things must be true for a bundle to see another
bundle's class: The class must be exported by the provider and must be
imported by the consumer.

Hope this helps

Regards
Felix

On 3/19/07, Tim Moloney <t....@verizon.net> wrote:
>
> Tim Moloney wrote:
> > I'm trying to use JAXB within a bundle that I'm writing but I'm not
> > having much luck.
> >
> > I can compile and start my bundle (after I load the jaxb-libs,
> > jax-impl, relaxngDatatype, and xsdlib bundles I wrapped).  However, I
> > get a runtime error ("my.domain.package" doesnt contain
> > ObjectFactory.class or jaxb.index) when I try to get a JAXB context.
> >
> > ObjectFactory is in my.domain.package (it's actually generated by
> > hyperjaxb2) and I've exported my.domain.package.* from my bundle, but
> > com.sun.xml.internal.bind.v2.ContextFactory.createContext() can't seem
> > to find it.
> >
> > Any thoughts on what else I may need to do?
> >
> > Thanks,
> >  Tim
>
> I forgot to mention that JAXB works outside Felix as expected.
>
> Tim
>
>

Re: Has anyone used JAXB within Felix?

Posted by Tim Moloney <t....@verizon.net>.
Tim Moloney wrote:
> I'm trying to use JAXB within a bundle that I'm writing but I'm not 
> having much luck.
>
> I can compile and start my bundle (after I load the jaxb-libs, 
> jax-impl, relaxngDatatype, and xsdlib bundles I wrapped).  However, I 
> get a runtime error ("my.domain.package" doesnt contain 
> ObjectFactory.class or jaxb.index) when I try to get a JAXB context.
>
> ObjectFactory is in my.domain.package (it's actually generated by 
> hyperjaxb2) and I've exported my.domain.package.* from my bundle, but 
> com.sun.xml.internal.bind.v2.ContextFactory.createContext() can't seem 
> to find it.
>
> Any thoughts on what else I may need to do?
>
> Thanks,
>  Tim

I forgot to mention that JAXB works outside Felix as expected.

Tim