7
votes

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 used 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?

1
First question is: why do you want to do that? There is no real notion of a classpath for a bundle, merely a set of classes that are accessible.Angelo van der Sijpt
Just to be clear: there is a bundle header known as Bundle-ClassPath (osgi core 3.2.1.4), but given your "java.class.path" example, this is probably not what you mean.Angelo van der Sijpt

1 Answers

2
votes

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