Here is the context: I have 2 osgi products running, one which is the main software (lets call it 'software') and the other which manages updates/installs/uninstalls of the first one, using p2. (lets call the second one 'updater')
I managed to make the updater install a feature into the software, meaning that the feature was successfully installed in the features directory and its bundles in plugins directory. Regarding p2 everything is good, the profile is updated with the new changes.
However it had absolutely no effect on the software, which didn't care of the new feature.
So I added some p2.inf files in my plugins with the instruction installBundle and this made my new bundles being added in the config.ini file which contains the list of bundles to load.
This makes me very close to the victory because when I restart the software, my new plugins are loaded by the framework. But.. I don't want to restart and I'm not supposed to have to since osgi is able install stuff in live.
Still fighting, my searching made me discover the simpleconfigurator which is responsible of loading the list of bundles from a file and giving them to the framework which will do everything it needs. But it does it only at the startup and I don't find any way or any doc to ask him to do refresh the list at runtime.
The only solution I've done so far is to call the update() method on the bundle org.eclipse.equinox.simpleconfigurator and then my bundles get recognized and work perfectly.
So right now, I have something working but I'd like to find a better solution and the reason that I'm telling the full story is because I'm surprised by the fact that, after battles with p2, I also need to fight with osgi to make it loading the new bundles..
Thanks for any help :)

- 1
- 1
-
Is there some reason why you're using p2 for this?? – Neil Bartlett Jul 10 '13 at 15:06
-
why not ? it was a technical choice when we designed the update system, and we wanted to have some repositories to let the user install new things, a rollback system (which is easy with the p2 profile), etc. – Kevin Jul 10 '13 at 15:32
-
1Well, I've found p2 very cumbersome and hard to use, whereas the standard OSGi R5 Repositories and Resolver specifications are well designed and powerful. Anyway, I asked because if you were developing something like an Eclipse RCP application or Eclipse SDK plugin then p2 would be pretty much unavoidable. – Neil Bartlett Jul 10 '13 at 18:48
2 Answers
I am not very familiar with p2. But it sound like you have two problems - you need some way to programatically deploy bundles into the OSGi container at run time and have the main application be aware of and use the functionality from those bundles.
For the first problem take a look at the selected answer on Programmatically Start OSGi (Equinox)?
For the second part you can use a ServiceListener - http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/ServiceListener.html - in your main application to listen for Services that implement a pre-defined interface. You main application should get notified whenever services are REGISTERED or UNREGISTERED at run time and can react accordingly.
you can find your bundle, and invoke bundle.update(InputStream input). http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/Bundle.html#update(java.io.InputStream)

- 101
- 1
- 4