Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Dynamic Class Loading
Dynamic Class Loading [message #702624] Tue, 26 July 2011 15:37 Go to next message
sschmitz is currently offline sschmitzFriend
Messages: 9
Registered: July 2011
Junior Member
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 22:03 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
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 12:12 Go to previous message
sschmitz is currently offline sschmitzFriend
Messages: 9
Registered: July 2011
Junior Member
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?
Previous Topic:Closing a view that is not in active Perspective
Next Topic:SWTBot headless problem
Goto Forum:
  


Current Time: Wed Apr 24 19:17:39 GMT 2024

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

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

Back to the top