Printing an OSGI feature class?

In a regular Java application, you can print the contents of the class path using

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

But how do I print the path to the OSGI classes created using the eclipse PDE wizard? In the activator, you can get the current package, for example:

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

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

But javadoc says findEntries DOES NOT use the class loader. Is there an easy way to see / print what is in the current package class path?

+6
classpath eclipse osgi
source share
1 answer

As others have pointed out, there really is no such thing as a “package class path” - that is the whole point of OSGi. :)

What can you do:

  • look at the headers of your packages to find out which packages it imports, and whether they are required or required

  • use PackageAdmin to search for packages that export packages with the given name

However, AFAIK PackageAdmin is deprecated and a new / enhanced mechanism for working with wired communications in 4.3 will appear.

It seems that your real motivation for this is to scan classes for finding and loading resources. The fact that this isn’t easy is a side effect of applying the borders of the module: you cannot have a fence and at the same time allow anyone to walk on the lawn. There was a standard service plan that scans packets on behalf of the client, but this seems to have been removed (not sure why - maybe, as a result of the new 4.3).

+2
source share

All Articles