views:

1036

answers:

2

I have an application that runs as a collection of OSGi bundles. I start it using a very small wrapper that embeds the Felix framework. The necessity of that wrapper irks me a little, as does the fact that it depends on Felix (whereas the application itself could run just as well in, say, Equinox), so I want to get rid of it, and use the default Felix launcher.

The only thing that the wrapper really does is passing the command line arguments into the launched OSGi framework, so that a bundle there can react upon them. Note that it does not actually parse the arguments, just pushes the String[] into my application.

Is there a standard way (or at least a Felix-standard way) to access command line parameters from a bundle, so that I can do away with the custom launcher?

+1  A: 

Probably not. I think the standard Felix launcher does some command line validation and only accepts the bundle cache dir as an argument. More than one argument and the launcher quits.

You may use system properties to pass information in the command line, and I think it works not only in felix but also in other osgi containers, but it probably makes your application not very user friendly.

jassuncao
Yes. "-Dthis -DandThat" seems to work, but it is really quite ugly...
Thilo
+2  A: 

Late answer but perhaps someone finds it useful.

I was having quite the same issue. My application runs in OSGi but I have external interfaces that I need to comply with which implies reading the command line arguments.

The key to this is something defined in the new OSGi specification 4.2, namely Framework Launching. You can read about it in the Draft spec (found under Draft on www.osgi.org) in the Life Cycle Layer section.

It's a standard way of launching an OSGi framework (any implementation that supports OSGi 4.2) from a stand-alone java application. The nifty thing is that you don't need to know which implementation you start (Felix, Equinox, ...) as long as it is found in the CLASSPATH.

This way, the your launcher application reads command line arguments, instantiates and starts an OSGi framework and pass the arguments to your bundle (any way you want). What you get in the launcher application is a Context to the framework from which you can communicate with your bundles.

As of Equinox 3.5M6 (I think, well at least M6) this is supported. The latest version of Apache Felix does also support this.

pakerfeldt