users@jersey.java.net

Re: SV: [Jersey] Is there a way to set what classloader JAXBContext uses when using Jersey?

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Fri, 6 Aug 2010 15:21:06 +0200

Hi Jimi,

Provider classes, such as the JAXB message body writers, are looked up
using the com.sun.jersey.spi.service.ServiceFinder and in that source
you will find the use of the thread context class loader.

I cannot explain the class loading differences in this respect with
JAXB, i guess Jira does something a little different to isolate
certain libraries, and the JAXB implementation is not visible from the
thread context class loader?


On Aug 6, 2010, at 3:07 PM, Jimi Hullegård wrote:

> Hi Moises,
>
> No, my JAXBContextResolved wasn't in the same package as my
> resourses, since I haven't seen any such directive in any Jersey/
> JAXB-documentation. But I just tried that and it didn't make any
> difference.
>
> And no, I have no Application class. And I have no idea on what that
> class should contain, and how I should make it available for Jersey.
> All Application-related discussions seems to asume that this takes
> place in a web application. But I use Jersey as a client only, and I
> have no servlet or any web.xml or something like that.
>

You need to register your ContextResolver<JAXBContext> implementation
explicitly with the client, as follows:

   ClientConfig cc = new DefaultClientConfig();
   cc.getClasses(MyContextResolver.class);
   Client c = Client.create(cc);

Paul.