Load a class of a fragment dynamically from a String [message #499431] |
Sun, 22 November 2009 09:44  |
Eclipse User |
|
|
|
Hello,
is there a chance to load a class with a String which consists the name of the package and the name of the class. But not the name of the plugin, which consists the class. But the plugin is loaded and activ.
I tried it with thw following code. But I get a ClassNotFoundException.
String className = aaa.test.TestClass;
Class <?> testClass = Class.forName(className);
What can I do, to get a instance of this class.
|
|
|
Re: Load a class of a fragment dynamically from a String [message #499437 is a reply to message #499431] |
Sun, 22 November 2009 10:26   |
Eclipse User |
|
|
|
Hi Michelle,
You have to export the package that delivers the class and import the package
in the plug-in that does the reflection (uses forname method). Instead of
Require-Bundle you use Import-Package.
here is a fragment from the MANIFEST.MF
Require-Bundle: org.eclipse.ui;bundle-version="3.4.1",
org.eclipse.core.runtime;bundle-version="3.4.0",
Import-Package: org.apache.james.mime4j;version="0.6.0",
org.apache.james.mime4j.codec;version="0.6.0",
Best Regards,
Wim Jongman
> Hello,
>
> is there a chance to load a class with a String which consists the name of
the package and the name of the class. But not the name of the plugin, which
consists the class. But the plugin is loaded and activ.
>
> I tried it with thw following code. But I get a ClassNotFoundException.
>
>
> String className = aaa.test.TestClass;
> Class <?> testClass = Class.forName(className);
>
> What can I do, to get a instance of this class.
|
|
|
Re: Load a class of a fragment dynamically from a String [message #499610 is a reply to message #499431] |
Mon, 23 November 2009 09:34  |
Eclipse User |
|
|
|
What are you trying to do, exactly? I mean where is the class coming from.
Usually you'll have an engine that needs to load contributions. i.e. the eclipse workbench loads contributed preference pages. In eclipse the pattern we use for that is Extension Points/Extensions.
i.e. the engine defines the ExtP and contributors (different plugins) define Extensions. In the Extension definition, the provide a class attribute, which is the FQCN (org.example.rcp.MyPrefPage). IConfigurationElement provides methods to instantiate a class correctly (from the providing bundle).
Will this pattern not work for you?
PW
|
|
|
Powered by
FUDForum. Page generated in 0.07072 seconds