Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Alternatives for deprecated IPluginDescriptor::getPluginClassLoader
Alternatives for deprecated IPluginDescriptor::getPluginClassLoader [message #52635] Mon, 07 November 2005 13:46 Go to next message
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
Hi, One of our plugins provides a facility where a proprietary-script can be executed. Running a script involves the following steps ..

STEP1. Translate script to a Java Class

STEP2. Compile the Java Class generated in step1 using javac (part of JDK).

STEP3. Reload the new class into VM with the help of a new instance of java.net.URLClassLoader. (Just instantiated for that sake and left for garbage collect immediately after the task is over.)

NOTE: The script could be changed by user many a times and can be executed many a times. (That leads to reloading the class more than one number of times. i.e, STEP3 should load new class to affect the changes)

We were able to get STEP3 working by some code like this ..

try {
	URLClassLoader newLoader = new URLClassLoader(getJavaClassPathURLList(),
						OurPlugin.getDefault().getDescriptor().getPluginClassLoader());			
	/* code related to loading new class etc.,
	..
	..
	*/	
	    
} catch (Throwable ex) {			
	throw new OurException("Could not execute script.\r\nSCRIPT_ERR:\r\n", ex);
			
} finally {			
	/* enable garbage collector to garbage the new class loader */
	System.gc();
}


This was when we were working with Eclipse 3.0 API. By that time itself IPluginDescriptor::getPluginClassLoader was deprecated and a suggestion was there with its javadoc to use Bundle::loadClass(String). Since Bundle::loadClass could not reload the same class again and again, we went for the solution with URLClassLoader.

Now that we are moving to the latest release Eclipse 3.1.1, I am looking for correct ways of doing the same without going for deprecated API.

Could anyone please direct me for correct ways of doing the above.

I had seen a solution like instantiating a new classloader from the ANT plugin which shipped with Eclipse 3.0; I do know that loading classes externally is dangerous, but my job needs that.

Thanks
~Venkat
Re: Alternatives for deprecated IPluginDescriptor::getPluginClassLoader [message #52662 is a reply to message #52635] Tue, 08 November 2005 10:25 Go to previous messageGo to next message
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
Hi, after going through the bug report https://bugs.eclipse.org/bugs/show_bug.cgi?id=65438 (not actually a bug), replacing IPluginDescriptor::getPluginClassLoader with OurPlugin.class.getClassLoader() worked fine. Thanks Rafael Chaves.

Thanks
Venkat
Re: Alternatives for deprecated IPluginDescriptor::getPluginClassLoader [message #53279 is a reply to message #52662] Wed, 16 November 2005 02:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jeff_nospam_mcaffer.ca.ibm.com

That approach may work in some cases but is certainly not guaranteed.
First, not all plugins have a plugin class. Second there is no guarantee
that a plugin's plugin class comes from that plugin (say that fast three
time!)

You are better off looking at PackageAdmin.getBundle(Class). Given this you
can write a wrapper classloader that backs onto the returned Bundle and
passes through calls like loadClass etc.

Jeff

"venkataramana" <venkataramanam@gmail.com> wrote in message
news:8161884.1131445546095.JavaMail.root@cp1.javalobby.org...
> Hi, after going through the bug report
https://bugs.eclipse.org/bugs/show_bug.cgi?id=65438 (not actually a bug),
replacing IPluginDescriptor::getPluginClassLoader with
OurPlugin.class.getClassLoader() worked fine. Thanks Rafael Chaves.
>
> Thanks
> Venkat
Re: Alternatives for deprecated IPluginDescriptor::getPluginClassLoader [message #53415 is a reply to message #53279] Wed, 16 November 2005 06:04 Go to previous messageGo to next message
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
Jeff, thanks for the remarks.
Will have a look into PackageAdmin.getBundle(..) as suggested.

Thanks again.
Venkat
Re: Alternatives for deprecated IPluginDescriptor::getPluginClassLoader [message #54553 is a reply to message #53415] Mon, 12 December 2005 16:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kai.klesatschke.googlemail.com

Venkataramana M wrote:
> Jeff, thanks for the remarks.
> Will have a look into PackageAdmin.getBundle(..) as suggested.
>
> Thanks again.
> Venkat

Hey Venkat,

how did you solve your problem? I have a similar situation here.

Regards Kai
Re: Alternatives for deprecated IPluginDescriptor::getPluginClassLoader [message #54895 is a reply to message #54553] Tue, 13 December 2005 03:24 Go to previous messageGo to next message
venkataramana m is currently offline venkataramana mFriend
Messages: 86
Registered: July 2009
Member
Kai, I haven't yet implemented as Jeff McAffer had suggested, but my situation was where an external Java Class which needs to be reloaded everytime it is created afresh, also needs to refer to the classes coming under the realm of the plugin which reloads the new java class (I think the statement is too long:-))
So I needed a way so that the new Java Class loaded into VM does not have problems referring to the plugin's class. In a way if plugin's classloader can be passed as parent classloader to an instance of URLClassloader, that solves my problem. So if my plugin class is MyPlugin, then MyPlugin.class.getClassloader() when passed to URLClassloader solved my problem temporarily.

URLClassLoader newLoader = new URLClassLoader(getJavaClassPathURLList(),
	MyPlugin.class..getPluginClassLoader());	


Hope that helps.

Thanks
~Venkat
Re: Alternatives for deprecated IPluginDescriptor::getPluginClassLoader [message #54949 is a reply to message #54895] Wed, 14 December 2005 06:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kai.klesatschke.googlemail.com

Venkataramana M schrieb:
> Kai, I haven't yet implemented as Jeff McAffer had suggested, but my situation was where an external Java Class which needs to be reloaded everytime it is created afresh, also needs to refer to the classes coming under the realm of the plugin which reloads the new java class (I think the statement is too long:-))
> So I needed a way so that the new Java Class loaded into VM does not have problems referring to the plugin's class. In a way if plugin's classloader can be passed as parent classloader to an instance of URLClassloader, that solves my problem. So if my plugin class is MyPlugin, then MyPlugin.class.getClassloader() when passed to URLClassloader solved my problem temporarily.
>
>
> URLClassLoader newLoader = new URLClassLoader(getJavaClassPathURLList(),
> 	MyPlugin.class..getPluginClassLoader());	
> 

>
> Hope that helps.
>
> Thanks
> ~Venkat
thanks I did it the same way. Don't know if
SomeBundle.class.getClassLoader() is the write way?! I hope this will me
get the bundles classloader always.
Re: Alternatives for deprecated IPluginDescriptor::getPluginClassLoader [message #57613 is a reply to message #54949] Tue, 24 January 2006 04:04 Go to previous message
Eclipse UserFriend
Originally posted by: jeff_nospam_mcaffer.ca.ibm.com

Note that there is a Bundle.loadClass() method. I strongly suggest using
this rather than depending on some way of introspecting and finding class
and then getting its classloader. If you really need an instance of
ClassLoader then you can create a class that just forwards to the relevant
methods on Bundle for loading classes and resources.

Jeff

"Kai Klesatschke" <kai.klesatschke@googlemail.com> wrote in message
news:dnoehp$th8$1@news.eclipse.org...
> Venkataramana M schrieb:
> > Kai, I haven't yet implemented as Jeff McAffer had suggested, but my
situation was where an external Java Class which needs to be reloaded
everytime it is created afresh, also needs to refer to the classes coming
under the realm of the plugin which reloads the new java class (I think the
statement is too long:-))
> > So I needed a way so that the new Java Class loaded into VM does not
have problems referring to the plugin's class. In a way if plugin's
classloader can be passed as parent classloader to an instance of
URLClassloader, that solves my problem. So if my plugin class is MyPlugin,
then MyPlugin.class.getClassloader() when passed to URLClassloader solved my
problem temporarily.
> >
> >
> > URLClassLoader newLoader = new URLClassLoader(getJavaClassPathURLList(),
> > MyPlugin.class..getPluginClassLoader());
> > 

> >
> > Hope that helps.
> >
> > Thanks
> > ~Venkat
> thanks I did it the same way. Don't know if
> SomeBundle.class.getClassLoader() is the write way?! I hope this will me
> get the bundles classloader always.
Previous Topic:Software update
Next Topic:Starting additional OSGI bundle in the console
Goto Forum:
  


Current Time: Thu Apr 25 23:10:57 GMT 2024

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

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

Back to the top