0
votes

I have a system setup where I am running Eclipse Equinox in a server-side application and in my Eclipse RCP Application. My goal is to take a plugin in the workspace and deploy it into the server-side app and I'm not sure how to go about it.

I know OSGI supports runtime bundle installs but would I have to compile my workspace project into a jar first? Is there an API I can use in Eclipse Runtime to say ..installBundle(String pathToJar or pathToProject)?

1
See the javadoc of BundleContext.installBundle(location) - Balazs Zsoldos
Thanks, I looked up the Javadoc, do you know how the location string works? Can I point to a non-compiled plugin project in my workspace to install or do I have to first build the plugin myself into a jar? I'm hoping I can do the install from source because I don't know how to build a plugin from my code. - Duncan Krebs
You can specify the location in the same format as the osgi.bundles setting in eclipse/configuration/configuration.ini accepts. "reference:" on the beginning of the URL means that the content of the bundle will not be copied to the working directory of the OSGi container but it will be used from the location. Folders that contain classes and the resources can be specified in this way, too (only with reference: in the beginning). - Balazs Zsoldos
Have a look at OSGi bundle development with bndtools. This is giving you immediate bundle creation during development time on every change/save. The created bundle can then be installed/updated inside your runtime via OSGi shell or Felix Webconsole. - Peter Kirschner

1 Answers

0
votes

This is an example I tested on eclipse equinox. If "plugins" is the name of the folder containing all your osgi bundles, a method to install and start a bundle from there is:

void installAndStartBundle(String bundlName) throws BundleException{
    BundleContext bundlecontext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
    Bundle b = bundlecontext.installBundle("file:plugins" + File.separator + bundleName);
    b.start();
}

where bundleName is the name with jar extension of the deployable bundle.

This is equivalent to the instructions from the osgi console

install file:plugins/<bundle name>.jar
start <bundle id>

In general, you might want to consider Apache Felix File Install as a more robust option.