OSGI bundles packaging and deployment

I created my first non trivial swing application based on OSGI. I deployed it on Apache Felix and Knopflerfish for testing purposes.

The swing application has about 130 classes, not huge classes. I tried to make a good design using couple of interfaces with some abstractions(docking framework abstraction, file system abstraction, gui components abstraction, plugin manager abstraction, etc.). After few days, I was satisfied with the design and started coding few concrete classes. I made sure that most of the code could be reused quickly in a non-OSGI environment.

In 4 days, I finished programming the core of the application. The only thing left was the gui main window. I wanted to use a docking framework(LGPL, BSD or Apache License).

Using docking frameworks such as MyDoggy or Flexdock in an OSGI environment looks complicated. Most of those libs make some static calls while trying to resolve images or configuration files. Sometimes some properties or other resources are stored in the META-INF folder of the jar files.

I was surprised to see that, as the library wasn't finding its default configuration file(from the classloader), it was looking for it in my home folder. There's no way to set the default properties using a static method without messing with the source code of MyDoggy (or maybe I didn't see a way).
With Apache Felix I couldn't import sun.awt package used in MyDoggy but I was able to do it with knopflerfish.

With Flexdock, I had an infinite loop, an exception which was thrown all the time, preventing the program to run. It was complaining about not being able to create an instance of the persistencemanager or something like that. Must have been some class loading issues using reflection calls.

I decided to use few JSplitPane at last and I could see the main window of the application, after few hours spent looking into those docking frameworks source code.

To test quickly I was using Apache Felix(embedded) in the application. I had my activators written but no OSGI manifests yet. Later I saw the bundles issues. I didn't want to embed some dependencies directly in my bundles. So I started browsing the web for "osgi bundles" and chatting on IRC. Some guys told me to look at Eclipse Orbit.

Eclipse Orbit is a community effort to create OSGI bundles for common third party librairies. It's a lot of work. I packaged few libraries and it took a bit to import and export the right packages.

The last thing left before going on with that swing application, is to add some listeners so that when a bundle is removed/updated, the GUI and some non visual parts are notified to update themselves.

Bookmark the permalink. RSS feed for this post.

8 Responses to OSGI bundles packaging and deployment

Richard said...

You should be able to import 'sun.awt' in Felix too, but Felix does not give you access to JVM implementation packages by default, since this would break modularity. If you need this, the best approach is to import it in your bundle and export it from the system bundle using the 'org.osgi.framework.system.packages' property. Another approach is to use the 'org.osgi.framework.bootdelegation' property to make it automatically available to bundles, but this isn't such a good thing since it makes it an implicit dependency.

Yves Zoundi said...

Thanks Richard. I ended up modifying the mydoggy source code to remove the sun proprietary package references. I was able to use mydoggy inside Felix.

Yves Zoundi said...

I managed to create easily bundles using the bnd tool for both Felix and MyDoggy. Flexdock seems to dump it's persistence data and native libraries in the user's home folder which is kind of annoying.

Robert said...

Did you consider that the application may be started multiple times? I'm currently searching for a solution how this can be achieved on top of Felix.

Angel Electrico said...

Hi Yves,

I've been working on a M$ Live Writer alternative...


And I'm trying to get it to work under OSGI as a bundle and I ran into the exact same problem as you with myDoggy. Where you able to fix the sun.awt problem using another option rather than fixing the source?


Angel Electrico said...

... I'm using knopplerfish

Angel Electrico said...

Thank you for leaving your comments in myDoggy.


You saved me a lot of work. I just compiled the class and repackage it into mydoggy-plaf.jar.


Yves Zoundi said...

Wow, it's been a while... I didn't update the thread with my results, but I did move forward.

Everything was working as expected( docking framework, plugin manager, etc.).

I submitted a patch to the maintainer(Angelo De Caro) and he incorporated a fix in the svn trunk. http://tinyurl.com/lyr4kx

I was able to get it to run on Apache Felix and Knopplerfish. I didn't try with Eclipse, I was running a 64bit jvm, so it was complicated for a custom launcher.

If you build mydoggy from trunk, I might be wrong but you should get the fix. If not, use the link provided by Angel. I think that I still have an OSGI copy for mydoggy 1.5.x on my hard drive, I could upload it if needed.

Swedish Greys - a WordPress theme from Nordic Themepark. Converted by LiteThemes.com.