且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有办法查看OSGi应用程序中的注册服务?

更新时间:2022-06-19 23:42:27

这取决于您是使用OSGi Shell进行交互还是通过应用程序进行编程.

It depends whether you mean interactively, using an OSGi shell, or programmatically from your application.

交互式

您可以使用 Equinox控制台.请参阅服务".要仅查看已部署的服务,您需要使用LDAP过滤器.这是一个示例:

You can use the Equinox console. See 'services'. To only see the services you have deployed you need to use an LDAP filter. Here's an example:

(objectClass=my.package.name.*)

也请参阅@Neil Bartlett的回答,因为您可以通过捆绑包ID进行约束(假设您知道它,但这很容易找到),因此答案可能会更容易.

Also see @Neil Bartlett's answer which might be easier as you can just constrain by bundle id (assuming you know it, but that's easy to find).

以编程方式

使用ServiceTracker方法. Neil也写了所有这一切,因此请确保也给他投票: )

Use the ServiceTracker approach. Neil also wrote all about this, so make sure to give him your upvotes too :)