将参数传递给OSGi应用程序 [英] Passing arguments to OSGi application

查看:88
本文介绍了将参数传递给OSGi应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个团队中,该团队正在转换一组Java应用程序以使用OSGi.以前,我们使用自己的自制软件类加载器系统,该系统与OSGi有一些相似之处,但这只是麻烦.我们希望,通过使用Apache Felix之类的系统,我们可以拥有一个运行更好的系统,而我们所需的支持工作却更少.

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.

我们一直在将构成应用程序的模块转换为OSGi捆绑软件,这与使用Spring DM无关. 但是,作为团队中的我,这是我的责任,因此,我们需要某种方式通过Maven(或Jenkins)之类的工具可靠地生成应用程序.绝对需要具有可重新分发的应用程序安装程序,该安装程序将为用户安装所有内容. (我们非常了解我们的用户群;他们想要一个简单的安装,安装后不会下载额外的东西,除非不是他们决定安装额外的插件,否则,这是另外一回事了.)我们不希望构建该应用程序在手动控制台上或使用GUI手动进行,因为手动处理很可能会遇到愚蠢的人为错误;我们想弄清楚它并调试一次 .

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.

此外,我们套件中的某些应用程序必须像常规应用程序"那样接受命令行参数. (有问题的应用程序在内部进行了大量处理,有时需要从其他过程(例如Web门户)中调用.)我知道这会导致默认的Felix main出现一些问题,默认情况下,Felix main仅允许命令行参数用于其自身目的.而不是提供默认情况下将其导出到分发包的方法. (我知道我们可以用shell脚本包装内容,以便将它们作为属性传递,但是…… ewwww ... 肯定有更好的方法.我怀疑制作一个导出的自定义main最好的方法是提供对命令行参数的访问权限的服务.)

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.)

所以,我的问题是自动构建整个OSGi应用程序的推荐方法是什么,我是否使用合理的方法来提供命令行参数?

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?

推荐答案

我猜您最好的选择是编写自己的main,专门完成您想要的.从OSGi R4.2开始,启动API是标准的并且非常简单.您可以从Felix的Main开始,因为它已经是通用的(即,它可以启动任何R4.2框架,例如Felix或Equinox)并按您的意愿进行更改.

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.

如果命令行参数表示配置属性,则可以将其推送到Config Admin中.否则,只需向他们展示您认为合适的方式即可.

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

这篇关于将参数传递给OSGi应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆