1

My ultimate goal is Invoking Eclipse plugin from Java. I see that an Eclipse plugin registers a class as Bundle-Activator in MANIFEST.MF. The start(BundleContext context) method will be called on this class. Where does this call come from?

Eclipse is made up of many repos that are mostly mirrored on GitHub. Some are deprecated and point to other repos. And it's a programming IDE and an OSGi framework at the same time? I find it hard to find the code for this core part of the framework that handles plugin loading. Where is it?

Daniel Darabos
  • 26,991
  • 10
  • 102
  • 114
  • 2
    A quick debug shows `start` being called from `org.eclipse.osgi.internal.framework.BundleContextImpl` in the `org.eclipse.osgi` plug-in. But the `start` method is not all that important, many plug-ins don't even use it. The reason the previous question has no answer is because calling a plugin from a plain Java app is next to impossible, you will end up having to write some version of most of the OSGi code as plug-ins expect all sorts of OSGi services to be available. – greg-449 Sep 16 '22 at 15:55
  • Thanks! I'll check it out! I was hoping I can just import some Eclipse stuff in my Java app to set up those OSGi services instead of implementing OSGi myself. Is that not going to work? – Daniel Darabos Sep 16 '22 at 18:20
  • I guess when you write "from Java" you mean a non OSGi java application. Is that correct? – Christian Schneider Sep 16 '22 at 18:33
  • A normal Java application, yes. What makes an OSGi application different from a non-OSGi application? I thought these Eclipse apps are also normal Java applications, they just use some fancy Eclipse class as the main class and that loads the plugins and stuff. – Daniel Darabos Sep 16 '22 at 18:38
  • 2
    OSGi applications are quite different from normal java applications. It is more like comparing spring and java. A proper OSGi application consist of loosely coupled bundles that interact with each other mainly via OSGi services. Typically this is defined similar to spring with annotations. The OSGi framework plus e.g. declatative services framework for annotation support then pulls up the classes and wires them together. Unfortunately in addition to OSGi being special. Eclipse is its own beast with special constructs and conventions. – Christian Schneider Sep 16 '22 at 19:11

1 Answers1

1

The project to interact with OSGi bundles is Eclipse Equinox. It is an implementation of the OSGi framework. You start equinox and load the bundle jar from there instead of putting them into the regular classpath.

Here you find some information how to do this in general: http://njbartlett.github.io/2011/07/03/embedding-osgi.html

You can then interact with the bundles from you plain java application. This is not an easy thing though.

What makes things even more complex is that Eclipse is not plain OSGi. Eclipse predates OSGi and many of the concepts are still not fully adapted to plain OSGi. So using eclipse plugins from a plain java application may be very hard.

I recommend to ask on the mailing list of the plugin you want to use if there is experience with using it outside eclipse.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • We'll see if I'll be able to get it working, but at least I'm making progress now! I've created a BundleContext with `org.eclipse.core.runtime.adaptor.EclipseStarter.startup([], null)` and I can install and start bundles. Thanks a lot! (It's not about a single plugin; I'm looking into whether it would be possible to support plugins made for KNIME in another application.) – Daniel Darabos Sep 16 '22 at 19:36