[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.newcomer] Re: Loading jars dynamic from plugins
|
"Franz Philipp Moser" <pm@xxxxxxxxx> wrote in message
news:fd596ac1b0f6931e8d8b9df5520147d8$1@xxxxxxxxxxxxxxxxxx
> Hi list,
>
> I tried to write a plugin that "loads/uses" jar files from an other
> plugin.
>
> plugin1 extention point loadJars and calls a function so the plugins get
> loaded. It has jars that should use Classes from plugin2 jars.
You're missing at least one verb in the first sentence, which is making it
hard for me to understand the question. I *think* you mean "plugin1
provides an extension point 'loadJars'...". But I'm not sure what you mean
by "calls a function so the plugins get loaded." What function? Which
plugins? It can't call a function unless it has already been loaded... do
you mean "calls a function so the jars get loaded"?
> plugin2 has the jars and extends the loadJars extension point implementing
> the interface defined by plugin1. It also exports the packages of the
> jars.
>
> The Problem I have is that Classes of plugin1 jars can not use the plugin2
> Classes stored in the plugin2 jars.
Right. Dependencies go one way only. If plugin2 extends an extension point
provided by plugin1, then plugin2 must depend on plugin1; that means that
plugin2 can see plugin1's exported classes, but plugin1 *CANNOT* see
plugin2's exported classes.
The way you work around this is that plugin1 has to expose interfaces, as
well as an extension point; plugin2's classes can implement those
interfaces. Then, within plugin1, you use
Platform.getExtensionRegistry().getExtensionPoint() to get an extension
point, navigate through it to get extensions, etc., and ultimately use
IConfigurationElement.createExecutableExtension() to ask plugin2 for a
concrete implementation of an interface that plugin1 exports.
The whole point is that plugin1 is never able to see the classes in plugin2,
it's only able to treat plugin2 as a factory for making concrete
implementations of interfaces or classes that it (plugin1) already knows
about.
There are some very specific cases where this mechanism isn't sufficient.
In those cases, you may end up creating your own URLClassLoader to load
classes (going outside of the OSGi classloading mechanism); or you may need
to look into "buddy classloading". Those should be seen as exceptional,
though.