Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » context class loader(BundleWebappClassLoader cannot load class)
context class loader [message #708182] Tue, 02 August 2011 14:46 Go to next message
Vladimir Stevanovic is currently offline Vladimir StevanovicFriend
Messages: 29
Registered: March 2010
Junior Member
BundleWebappClassLoader is set as the thread context class loader. I understood that it was created by synthetic context bundle, which imports all bundles in the scope, so context class loader would have to load any class from the scope.
I'm using some third party library, which uses classloader.loadClass() method and it cannot find the class. And, when thread context loader (BundleWebappClassLoader ) is inspected in the debugger, the field "classes" is empty!
Bug?
Re: context class loader [message #708198 is a reply to message #708182] Tue, 02 August 2011 15:03 Go to previous messageGo to next message
Hristo Iliev is currently offline Hristo IlievFriend
Messages: 156
Registered: May 2010
Location: Sofia, Bulgaria
Senior Member

Do you mean that the third party library uses the context class loader for loading? If so it should be able to find the resources accessible by the synthetic context.

In other words the library should explicitly use the context class loader, since Java will not make use of it by default.
Re: context class loader [message #708202 is a reply to message #708198] Tue, 02 August 2011 15:06 Go to previous messageGo to next message
Vladimir Stevanovic is currently offline Vladimir StevanovicFriend
Messages: 29
Registered: March 2010
Junior Member
Yes it uses the context class loader, but the loader doesn't load the class.
Re: context class loader [message #708331 is a reply to message #708202] Tue, 02 August 2011 17:45 Go to previous messageGo to next message
Hristo Iliev is currently offline Hristo IlievFriend
Messages: 156
Registered: May 2010
Location: Sofia, Bulgaria
Senior Member

Can you check if the class can be loaded from the any loader in the user region (clload) and from the loader of the bundle/webapp (clload with id) and post the results?

You can find how to do this in Virgo FAQ.

[Updated on: Tue, 02 August 2011 20:00]

Report message to a moderator

Re: context class loader [message #708811 is a reply to message #708331] Wed, 03 August 2011 07:39 Go to previous messageGo to next message
Vladimir Stevanovic is currently offline Vladimir StevanovicFriend
Messages: 29
Registered: March 2010
Junior Member
I've checked and class is loaded by several bundle loaders, but particular bundle cannot load the class.

The "third part library" is actually a javax.xml.transform in the org.eclipse.osgi bundle. The context class-loading is performed in the FactoryFinder.

When I replaced the original context classloader, and put one of the bundle classloaders that can load the class, everything worked, so I guess the problem is in BundleWebappClassLoader.
Re: context class loader [message #708888 is a reply to message #708811] Wed, 03 August 2011 09:01 Go to previous messageGo to next message
Hristo Iliev is currently offline Hristo IlievFriend
Messages: 156
Registered: May 2010
Location: Sofia, Bulgaria
Senior Member

If your bundle cannot load the needed class what you can do is to:

  • extend your web classpath header to include the resource
  • import the needed class from another bundle

[Updated on: Wed, 03 August 2011 09:01]

Report message to a moderator

Re: context class loader [message #709004 is a reply to message #708888] Wed, 03 August 2011 11:48 Go to previous messageGo to next message
Vladimir Stevanovic is currently offline Vladimir StevanovicFriend
Messages: 29
Registered: March 2010
Junior Member
Ok, but I still don't understand why is BundleWebappClassLoader set as context classloader. What about classloader from the synthetic context bundle?
I thought that synthetic context CL is always set as a thread context classloader, as it was stated here:
http://underlap.blogspot.com/2011/02/thread-context-class-loading-in-virgo.html

[Updated on: Wed, 03 August 2011 11:48]

Report message to a moderator

Re: context class loader [message #709088 is a reply to message #709004] Wed, 03 August 2011 13:46 Go to previous messageGo to next message
Hristo Iliev is currently offline Hristo IlievFriend
Messages: 156
Registered: May 2010
Location: Sofia, Bulgaria
Senior Member

The synthetic context is used for PAR or scoped plan. Virgo builds a synthetic bundle and sets its loader as context class loader for all artefacts in the scope.

What's the packaging you are using - is it a PAR or a plan? Do you have a web app inside the PAR/plan?
Re: context class loader [message #709121 is a reply to message #709088] Wed, 03 August 2011 14:17 Go to previous messageGo to next message
Vladimir Stevanovic is currently offline Vladimir StevanovicFriend
Messages: 29
Registered: March 2010
Junior Member
I'm using PAR packaging, with one WAB bundle and several regular bundles.
Re: context class loader [message #709807 is a reply to message #709121] Thu, 04 August 2011 10:24 Go to previous messageGo to next message
Hristo Iliev is currently offline Hristo IlievFriend
Messages: 156
Registered: May 2010
Location: Sofia, Bulgaria
Senior Member

The webapp classloader (CL) is set by Tomcat on request (as by spec). Therefore the synthetic thread context CL from the PAR is overwritten with the webapp one. There may be applications that rely on this behaviour so we can't do much in this direction.

One thing that comes to my mind is to add the needed import(s) to your webapp so the FactoryFinder can load the class from the webapp CL.
Re: context class loader [message #709817 is a reply to message #709807] Thu, 04 August 2011 10:41 Go to previous messageGo to next message
Vladimir Stevanovic is currently offline Vladimir StevanovicFriend
Messages: 29
Registered: March 2010
Junior Member
Thanks for the explanation.
I'm just wondering is there any way to obtain synthetic thread context CL, in case I'd like to replace (and later to restore) the web CL ?
Re: context class loader [message #709971 is a reply to message #709817] Thu, 04 August 2011 14:44 Go to previous messageGo to next message
Hristo Iliev is currently offline Hristo IlievFriend
Messages: 156
Registered: May 2010
Location: Sofia, Bulgaria
Senior Member

Unfortunately there's no API to do this.

I created enhancement [1] to cover this as well as bug [2] so we can document your question for the scope and context class loaders.

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=353899
[2] https://bugs.eclipse.org/bugs/show_bug.cgi?id=353897
Re: context class loader [message #710009 is a reply to message #709971] Thu, 04 August 2011 15:24 Go to previous message
Vladimir Stevanovic is currently offline Vladimir StevanovicFriend
Messages: 29
Registered: March 2010
Junior Member
Great,
thanks
Previous Topic:Virgo 3.0.0.RC2 available
Next Topic:Application Deployer crashing on undeploy
Goto Forum:
  


Current Time: Fri Apr 19 22:49:37 GMT 2024

Powered by FUDForum. Page generated in 0.03840 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top