打印OSGI包类路径? [英] Printing OSGI bundle classpath?

查看:139
本文介绍了打印OSGI包类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在普通的java应用程序中,可以打印类路径的内容:

In a normal java application its possible to print the content of the classpath with:

String ss = System.getProperty("java.class.path");
System.out.println(ss);

但是如何打印使用eclipse PDE向导创建的OSGI包的类路径?在激活器中,可以获得当前的捆绑包,如:

But how do I print the classpath of an OSGI bundle created using the eclipse PDE wizard? In the activator its possible to get the current bundle like:

public void start(BundleContext context)throws Exception {
super.start(context);
plugin = this;

public void start(BundleContext context) throws Exception { super.start(context); plugin = this;

Bundle b  = context.getBundle();
 // java doc: This bundle's class loader is not used to search for entries. 
b.findEntries(path, filePattern, recurse)

但是,javadoc说findEntries不使用类加载器。有没有任何简单的方法来查看/打印当前bundle的类路径?

But the javadoc says that the findEntries does NOT use the class loader. Is there any simple way to see/prints what is on the current bundle's classpath?

推荐答案

正如其他人已经表示真的没有像捆绑类路径这样的东西 - 这是OSGi的整体。 :)

As others have indicated there is really no such thing as a "bundle classpath" - that's the whole point of OSGi. :)

您可以做的是:


  • 您的包的标题,以查看其导入的包,以及是否需要或强制

  • look at your bundle's headers to see which packages it imports, and whether they are required or mandatory

使用PackageAdmin查找导出包名称的捆绑包

use PackageAdmin to find bundles that export packages with a given name

然而,AFAIK PackageAdmin已被弃用,将在4.3中使用新的/扩展机制来处理捆绑布线。

However AFAIK PackageAdmin is deprecated and there will be a new/extended mechanism to work with bundle wiring in 4.3.

似乎你真正的动机是通过类路径扫描来查找&负载资源。这是不容易实现的事实是强制模块界限的副作用:你不能有一个围墙,同时允许任何人走在草坪上。
有一个标准服务的计划,代表一个客户端扫描捆绑,但似乎已被撤回(不知道为什么 - 也许是新的4.3的东西的结果)。

It seems like your real motivation for this is classpath scanning to find & load resources. The fact that this is not easily possible is a side effect of enforcing module boundaries: you can't have a fence and at the same time allow anyone to walk on the lawn. There was a plan for a standard service that scans bundles on behalf of a client, but that seems to have been withdrawn (not sure why - maybe as consequence of the new 4.3 stuff).

这篇关于打印OSGI包类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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