You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Richard Martin <bo...@googlemail.com> on 2008/06/30 18:08:51 UTC

Classloader issue on wrapped project

Hello,

I am trying to wrap a project that has a huge number of dependent
jars.  Jars that only this project will use so I took to using BND and
including them all.  This takes a bit of time to build each time, like
5 minutes but it does give me a nice single drop in jar.

The problem I have is that the things I am wrapping up are cfx web
services.  I have never used this stuff or really seen the code I just
have the jars.  I have been stepping through what goes on and it seems
to be a classloader issue:

Basically javax.xml.ws.spi.Provider calls find on FactoryFinder
passing in a property to look for.  This property is
"javax.xml.ws.spi.Provider".

Finder then uses this property and creates a classloader using the
current thread, it then generates a string
("META-INF/services/javax.xml.ws.spi") which is a file in my wrapped
jar that contains the location of the cfx ProviderImpl.  This location
is then used to load the class with the classloader reference it has
and return an instance.  If this file can't be found it looks for a
system property of the same name.

The problem I am having is this code cannot seem to find either the
file in services folder, or if I set the system property manually it
then can't find the class.  I'm guessing this is some classloader
issue, everything works fine if I run this project not as a plugin.  I
hope some of that made sense.

Is there something I can do in Felix or my wrapped jar to help this
code find the correct classpath.

Cheers
Bob

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Classloader issue on wrapped project

Posted by Richard Martin <bo...@googlemail.com>.
Thank for that Karl, I finally got round to trying it and it worked perfectly.

Cheers
Bob

On 6/30/08, Karl Pauls <ka...@gmail.com> wrote:
> Try to set the context classloader to the classloader of your bundle
>  before the call that fails i.e.,
>
>  ClassLoader tccl = Thread.currentThread().getContextClassLoader();
>  try
>  {
>     Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
>     // call to code that instigates the classloader
>  }
>  finally
>  {
>     Thread.currentThread().setContextClassLoader(tccl);
>  }
>
>  Notice that in this case your bundle needs to import the missing
>  package as well (unless it is provided inside the bundle).
>
>  regards,
>
>  Karl
>
>
>  On Mon, Jun 30, 2008 at 6:08 PM, Richard Martin
>  <bo...@googlemail.com> wrote:
>  > Hello,
>  >
>  > I am trying to wrap a project that has a huge number of dependent
>  > jars.  Jars that only this project will use so I took to using BND and
>  > including them all.  This takes a bit of time to build each time, like
>  > 5 minutes but it does give me a nice single drop in jar.
>  >
>  > The problem I have is that the things I am wrapping up are cfx web
>  > services.  I have never used this stuff or really seen the code I just
>  > have the jars.  I have been stepping through what goes on and it seems
>  > to be a classloader issue:
>  >
>  > Basically javax.xml.ws.spi.Provider calls find on FactoryFinder
>  > passing in a property to look for.  This property is
>  > "javax.xml.ws.spi.Provider".
>  >
>  > Finder then uses this property and creates a classloader using the
>  > current thread, it then generates a string
>  > ("META-INF/services/javax.xml.ws.spi") which is a file in my wrapped
>  > jar that contains the location of the cfx ProviderImpl.  This location
>  > is then used to load the class with the classloader reference it has
>  > and return an instance.  If this file can't be found it looks for a
>  > system property of the same name.
>  >
>  > The problem I am having is this code cannot seem to find either the
>  > file in services folder, or if I set the system property manually it
>  > then can't find the class.  I'm guessing this is some classloader
>  > issue, everything works fine if I run this project not as a plugin.  I
>  > hope some of that made sense.
>  >
>  > Is there something I can do in Felix or my wrapped jar to help this
>  > code find the correct classpath.
>  >
>  > Cheers
>  > Bob
>  >
>
> > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>  > For additional commands, e-mail: users-help@felix.apache.org
>  >
>  >
>
>
>
>
>  --
>  Karl Pauls
>  karlpauls@gmail.com
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>  For additional commands, e-mail: users-help@felix.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Classloader issue on wrapped project

Posted by Karl Pauls <ka...@gmail.com>.
Try to set the context classloader to the classloader of your bundle
before the call that fails i.e.,

ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try
{
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    // call to code that instigates the classloader
}
finally
{
    Thread.currentThread().setContextClassLoader(tccl);
}

Notice that in this case your bundle needs to import the missing
package as well (unless it is provided inside the bundle).

regards,

Karl

On Mon, Jun 30, 2008 at 6:08 PM, Richard Martin
<bo...@googlemail.com> wrote:
> Hello,
>
> I am trying to wrap a project that has a huge number of dependent
> jars.  Jars that only this project will use so I took to using BND and
> including them all.  This takes a bit of time to build each time, like
> 5 minutes but it does give me a nice single drop in jar.
>
> The problem I have is that the things I am wrapping up are cfx web
> services.  I have never used this stuff or really seen the code I just
> have the jars.  I have been stepping through what goes on and it seems
> to be a classloader issue:
>
> Basically javax.xml.ws.spi.Provider calls find on FactoryFinder
> passing in a property to look for.  This property is
> "javax.xml.ws.spi.Provider".
>
> Finder then uses this property and creates a classloader using the
> current thread, it then generates a string
> ("META-INF/services/javax.xml.ws.spi") which is a file in my wrapped
> jar that contains the location of the cfx ProviderImpl.  This location
> is then used to load the class with the classloader reference it has
> and return an instance.  If this file can't be found it looks for a
> system property of the same name.
>
> The problem I am having is this code cannot seem to find either the
> file in services folder, or if I set the system property manually it
> then can't find the class.  I'm guessing this is some classloader
> issue, everything works fine if I run this project not as a plugin.  I
> hope some of that made sense.
>
> Is there something I can do in Felix or my wrapped jar to help this
> code find the correct classpath.
>
> Cheers
> Bob
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>



-- 
Karl Pauls
karlpauls@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org