Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Load a class of a fragment dynamically from a String
Load a class of a fragment dynamically from a String [message #499431] Sun, 22 November 2009 14:44 Go to next message
Michelle Davidson is currently offline Michelle Davidson
Messages: 41
Registered: August 2009
Member
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 15:26 Go to previous messageGo to next message
Wim Jongman is currently offline Wim Jongman
Messages: 418
Registered: July 2009
Senior Member
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 14:34 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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


Previous Topic:classpath problems
Next Topic:Can't get rid of jre in exported product
Goto Forum:
  


Current Time: Wed Sep 17 23:40:01 GMT 2014

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

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