Alternatives for deprecated IPluginDescriptor::getPluginClassLoader [message #52635] |
Mon, 07 November 2005 08:46  |
Eclipse User |
|
|
|
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 #57613 is a reply to message #54949] |
Mon, 23 January 2006 23:04  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.06334 seconds