Passing arguments to OSGi application

牧云@^-^@ 提交于 2019-12-22 10:36:59

问题


I'm in a team that is converting a suite of Java applications to use OSGi. Previously, we used our own home-brew class loader system that has some similarities to OSGi, but it was nothing but trouble; we expect that by moving to using a system like Apache Felix we can have a system that works better while requiring less overall effort on our part to support.

We have been converting the modules that make up the applications into OSGi bundles, a largely painless affair with the use of Spring DM. However, we — well, I as it's my responsibility in the team — need some way to reliably produce applications from this via a tool like Maven (or Jenkins); having a redistributable application installer that will install everything for the user is an absolute requirement. (We know our userbase fairly well; they want a simple install that won't download extra things after installation, well, not unless they decide to install extra plugins, but that's another story.) We do not wish to have to build the application manually at a console, or by using a GUI, as manual processes are too likely to run into silly human errors; we want to get it right and debugged once.

Moreover, some of the applications in our suite have to take command line arguments “like a conventional application”. (The application in question does significant processing internally, and sometimes needs to be invoked from other processes, such as web portals.) I know this causes some issues with the default Felix main, which only allows command line arguments for its own purposes instead of providing a way by default to export those to the bundles. (I know we could wrap things with a shell script so as to pass them in as properties, but… ewwww… there's got to be a better way. I suspect that making a custom main that exports a service providing access to the command line arguments is the best method.)

So, my question is what is a recommended way of building whole OSGi applications automatically, and am I using a reasonable approach to provide the command line arguments?


回答1:


I'm guessing your best option is to write your own main that does specifically what you want. Since OSGi R4.2 the launching API is standard and pretty straightforward. You can just start from Felix' Main since it is already generic (i.e., it can launch any R4.2 framework, such as Felix or Equinox) and change it how you wish.

If the command line args represent configuration properties, you could just push them into Config Admin. Otherwise, just expose them how you see fit.




回答2:


The Apache Sling Maven Launchpad Plugin generates a finished OSGi app from a list of bundles to include, and the Sling installer can be used to include initial configurations as well.

Even though they come from the Sling project, those module do not require your app to use the Sling app model, they are just used to build, launch and configure it.




回答3:


For your arguments, use metatype. It will allow your bundles to load with default values and when the user configures the bundle via the web console or config files, metatype will inject the values into your variables. An installer would also be able to set these values at install time via the config files.



来源:https://stackoverflow.com/questions/7132866/passing-arguments-to-osgi-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!