Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Plugable Swing – A Hello World OSGi Example

DZone's Guide to

Plugable Swing – A Hello World OSGi Example

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

There are a lot of OSGi applications available, but a minority of them is aimed at the client side. Here I will list some on Swing:

  1. http://felix.apache.org/site/apache-felix-application-demonstration.html
  2. http://danielrohe.wordpress.com/2009/04/01/swing-application-on-osgi/
  3. http://www.toedter.com/blog/?p=33
  4. http://code.google.com/p/osgi-in-action/
  5. sip-communicator

Today I tried the same and had luck. It was very fast (~1h) to get all working what I wanted, because I shamelessly stole the code from the example of Apache Felix. It is even more easier than this example but should have the same effect: it shows how one could use OSGi even for a Swing application.

There is a host application called Swing On OSGi – Host with one JMenu which does not change (static) and one (dynamic) JMenu which could be changed from the available plugins (here only one: Swing On OSGi – PluginTest). The source code (Apache License 2) can be checkout via

svn checkout https://timefinder.svn.sourceforge.net/svnroot/timefinder/branches/swingosgi swingosgi

… you will need maven. After ‘mvn install’ for both projects you will only need to start the host application via your IDE or via

java -jar target/host-1.0.0.jar

Then if you see the “dynamic menu” with one menu entry (which was added from the plugin) all is fine:

helloOSGiWorld

If you have problems while building this send me an email or comment here.

I got the plugins even working in my timetabling application TimeFinder which uses the client-side framework called Spring Rich Client. The first plugin for Spring Rich Client - read more.

From http://karussell.wordpress.com

Are you using Bitbucket to accomplish your company's mission? Share your company’s mission with #Forthecode for a chance to be featured on our homepage, our social media channels, or win a free t-shirt!

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}