开发者

Printing OSGI bundle classpath?

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

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;

Bundle b  = context.getBundle();
 // java doc: This bundle's class loader is not u开发者_JAVA百科sed to search for entries. 
b.findEntries(path, filePattern, recurse)

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?


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

What you can do is:

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

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

However AFAIK PackageAdmin is deprecated and there will be a new/extended mechanism to work with bundle wiring in 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜