Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Load a class at runtime
Load a class at runtime [message #309287] Mon, 23 October 2006 08:40 Go to next message
Eclipse UserFriend
Originally posted by: samuel.braun.ntb.ch

Hello

I have the following problem:
In my Eclipse plugin I want to load a class with Class.forName(...) at
runtime. The class which should be loaded is part of another plugin. I
always get the ClassNotFoundException back. I can't add the plugin (which I
want to load the class from) into the required plugins list of the plugin
which should load the class, because the plugin which I want to load the
class from requires the plugin which should load the class and then a cycle.
I also tried to load the class via an URLClassLoader but without success, I
think I do something wrong...

How can I get this to work?

Thanks in advance
Samuel
Re: Load a class at runtime [message #309288 is a reply to message #309287] Mon, 23 October 2006 08:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Platform.getBundle("com.my.other.bundle").loadClass("at.my.OtherClass ").newInstance();

Tom

Samuel Braun schrieb:
> Hello
>
> I have the following problem:
> In my Eclipse plugin I want to load a class with Class.forName(...) at
> runtime. The class which should be loaded is part of another plugin. I
> always get the ClassNotFoundException back. I can't add the plugin (which I
> want to load the class from) into the required plugins list of the plugin
> which should load the class, because the plugin which I want to load the
> class from requires the plugin which should load the class and then a cycle.
> I also tried to load the class via an URLClassLoader but without success, I
> think I do something wrong...
>
> How can I get this to work?
>
> Thanks in advance
> Samuel
>
>
>
Re: Load a class at runtime [message #309293 is a reply to message #309288] Mon, 23 October 2006 12:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: samuel.braun.ntb.ch

Hello Tom

> Platform.getBundle("com.my.other.bundle").loadClass("at.my.OtherClass ").newInstance();
Thanks for your help. That was the thing I've been looking for...

Greets Samuel
Re: Load a class at runtime [message #309296 is a reply to message #309287] Mon, 23 October 2006 13:40 Go to previous message
Eclipse UserFriend
Originally posted by: wharley.bea.com

"Samuel Braun" <samuel.braun@ntb.ch> wrote in message
news:ehid86$6po$1@utils.eclipse.org...
> Hello
>
> I have the following problem:
> In my Eclipse plugin I want to load a class with Class.forName(...) at
> runtime. The class which should be loaded is part of another plugin. I
> always get the ClassNotFoundException back. I can't add the plugin (which
> I
> want to load the class from) into the required plugins list of the plugin
> which should load the class, because the plugin which I want to load the
> class from requires the plugin which should load the class and then a
> cycle.
> I also tried to load the class via an URLClassLoader but without success,
> I
> think I do something wrong...
>
> How can I get this to work?


Tom's suggestion may be appropriate depending on the specifics of your case.
But in general, if plugin B depends on plugin A, and plugin A wants to load
a class from plugin B, the way it is done is with extension points. That
is, A exposes an extension point; B declares that it extends that extension
point; and then at runtime A uses the plugin registry to create the class
from B.

The method call to look at is
IConfigurationElement.createExecutableExtension().
Previous Topic:How to present Statistics
Next Topic:assigning my own folder icon besides Eclipse's default ones
Goto Forum:
  


Current Time: Sat May 10 03:45:24 EDT 2025

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

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

Back to the top