Pluggable Spring RC? (OSGi with Spring Rich Client)
My last post was about pure Swing, which could be easily OSGified. OSGi technology can be used to hotdeploy or undeploy jar files to your application server (at the moment only Spring’s server is suggested) or simply to update your Swing application at runtime or write plugins for them. I don’t know for sure, but it seems to me that Eclipse is the most prominent user of OSGi (equinox is one implementation of the specification…) as desktop application, although NetBeans can now use OSGi bundles.
(BTW: do you know a funny myth where the small “i” from OSGi could come from? No? Read the comments here!)
In the last post I show you several swing applications, which were successfully OSGified, today I would like to list Swing- or Eclipse-based applications which use Spring Dynamic Modules:
- https://spar.dev.java.net/
- http://sourceforge.net/projects/agilercp/
- http://max-server.myftp.org/trac/mp3m/ eclipse rcp
- http://max-server.myftp.org/trac/pm swing app framework, even webstart will work here
Then today, in contrast to my last post, I would like to show you an identical solution for the Spring Rich Client project.
Why should I use another framework on the top of OSGi? This is
simple: Spring DM provides several nice features, like no dependency on
the OSGi implementation (felix, equinox, knopflerfish)
and even no one on OSGi at all. Everything (and think) is a bean, like
always! But why Spring DM? Why not Declarative Services from OSGi
itself or Apache iPOJO? This is simple: I don’t know the others and Spring Rich Client cries for the Spring solution
But to make this short story very short: after struggling the last two days to get Spring Dynamic Modules integrated with Spring Rich Client I gave it up and tried the pure OSGi solution – and – it works. It might be an ugly solution for all those of you who like dependency injection, but this can be optimized later. Today this might be the first plugin for Spring Rich Client – ever:

The button “say hello” with its JOptionPane message was installed through the dynamically loaded plugin. The source code is nearly identical to the one in my previous post. Just add the Spring RC startup before you grab the menu from the application to create a MenuTracker, which calls the MenuService(=plugin):
@Override
public void start(BundleContext context) throws Exception {
startup.start();
menuTracker = new MenuTracker(context, Application.instance().getActiveWindow().getControl().getJMenuBar().getMenu(1));
menuTracker.open();
}
The source is available from my TimeFinder project via:
svn checkout -r 595 https://timefinder.svn.sourceforge.net/svnroot/timefinder/trunk timefinder
Be sure to start the application from de.timefinder.core.osgi.Activator (main method!).
I hope this post inspired someone to be the first one with Spring DM + Spring RC marriage … or sb. suggests working examples how Spring DM could be started from command line or from NetBeans.
From http://karussell.wordpress.com
One spare time killer for me is my timetabling open source project TimeFinder. I work for Pannous GmbH where we create Software with Java, Ruby and C#. Peter is a DZone MVB and is not an employee of DZone and has posted 19 posts at DZone. You can read more from them at their website.
- Login or register to post comments
- 1789 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)









