Dynamic Class Loading [message #702624] |
Tue, 26 July 2011 11:37  |
Eclipse User |
|
|
|
Hey there,
I'm facing a problem concerning dynamic class loading. I have a file Algorithm.java (pastebin . com/ CdGXdPFw) which is compiled by an instance of the javax.tools.JavaCompiler API. After that it's supposed to be loaded and a new instance is supposed to be created. All this takes place in a RCP project, let's call it VM.
The algorithm needs (as you can see in the source code) some datatypes from other plugins, let's call one of these other plugins "graph". However, the graph-plugin must not appear in the required-plugins section of VM's MAINFEST.MF.
This is where my problem lies:
I try to create an instance of Algorithm using this code:
algoInst = (AbstractAlgo) algoClass.getConstructors()[0].newInstance();
But it gives me class loading errors: pastebin . com/ k18gcpKS
So i tried to created a URLClassLoader with the URL to the Graph package et voila, this works:
loader.loadClass("de.unisiegen.informatik.bs.alvis.graph.datatypes.PCGraph"));
Even when I tried to call newInstance like this:
algoInst = (AbstractAlgo) Class.forName(algoClass.getName(), false, loader).getConstructors()[0].newInstance();
it does not work, although this loader is able to load PCGraph...
How do I get the instance of Algorithm using this class loader? I'm probably missing some RCP/ClassLoading-Basics here and need another pair of eyes...
Thanks for your help!
|
|
|
(no subject) [message #703769 is a reply to message #702624] |
Wed, 27 July 2011 18:03   |
Eclipse User |
|
|
|
Hi,
Yes classloader tricks are a no-go in OSGi/RCP.
Your binaries are not visible but I am guessing that your graps can come and
go. I think you should look at OSGi dynamic services or at Extension Points.
Basically, a graph bundle should register itself through an OSGi service or
an Extension point where it can be picked up by the VM plugin.
Again, do not fiddle with the classloader.
Regards,
Wim
> Hey there,
>
> I'm facing a problem concerning dynamic class loading. I have a file
Algorithm.java (pastebin . com/ CdGXdPFw) which is compiled by an instance of
the javax.tools.JavaCompiler API. After that it's supposed to be loaded and a
new instance is supposed to be created. All this takes place in a RCP
project, let's call it VM.
> The algorithm needs (as you can see in the source code) some datatypes from
other plugins, let's call one of these other plugins "graph". However, the
graph-plugin must not appear in the required-plugins section of VM's
MAINFEST.MF.
> This is where my problem lies:
> I try to create an instance of Algorithm using this code:
>
> algoInst = (AbstractAlgo) algoClass.getConstructors()[0].newInstance();
>
> But it gives me class loading errors: pastebin . com/ k18gcpKS
>
> So i tried to created a URLClassLoader with the URL to the Graph package et
voila, this works:
>
loader.loadClass("de.unisiegen.informatik.bs.alvis.graph.datatypes.PCGraph"));
>
> Even when I tried to call newInstance like this:
> algoInst = (AbstractAlgo) Class.forName(algoClass.getName(), false,
loader).getConstructors()[0].newInstance();
>
> it does not work, although this loader is able to load PCGraph...
>
> How do I get the instance of Algorithm using this class loader? I'm
probably missing some RCP/ClassLoading-Basics here and need another pair of
eyes...
>
> Thanks for your help!
|
|
|
Re: (no subject) [message #705087 is a reply to message #703769] |
Fri, 29 July 2011 08:12  |
Eclipse User |
|
|
|
Thank you for your answer!
I took your advice and stopped messing with class loaders.
The "solution" (more of a workaround, but the project is due in a month, so I can't waste any more time on this) was pretty simple:
I just put "DynamicImport-Package: *" in the VM's MANIFEST.MF and now it works fine.
Can I set this thread to 'solved' by myself?
|
|
|
Powered by
FUDForum. Page generated in 0.04357 seconds