问题
I'm starting a project writing OSGi bundle and using Maven as the build management tool. My understanding is for an OSGi bundle you can choose which package you would like to keep private/public.
Here is the question:
- If I am depending on a bundle that declares
com.examplepackage as exported package and declarescom.example.internalas private package, is there any way, during build time, to detect use ofcom.example.internal(build should fail)?
It would be awesome if that can be detected during development time by Eclipse, but I highly doubt it can.
回答1:
One option is to use Eclipse's Plugin Development Environment (PDE), an OSGi-aware set of tools. It won't let you compile against internal packages, so it gives you the development-time checking. Unlike maven's bundle plugin, it's manifest-first rather than code first, which isn't to everyone's taste.
To integrate PDE with Maven, the best bet is to use the Maven Tycho plugin. This gives you a fully OSGi-aware compilation stage in Maven.
回答2:
In think you will find a lot of support for this in bnd(tools). In general, I find these culprits by watching the Import-Package statement, which is nicely visualized in bndtools. There is some support in bnd(tools) to generate warnings/errors when an import package has no import range, which happen when you import a private or non-existent package.
来源:https://stackoverflow.com/questions/10954288/osgi-and-maven-detect-use-of-private-package