What is the standard way to bundle OSGi dependent libraries?

早过忘川 提交于 2019-11-28 00:18:16

I prefer to not embed the dependent jars (yes it is possible). It causes two problems,

1) There is no reuse of this code. Many bundles may simply do the same thing (embed the same jar) and you end up with the same jar installed many times. You can argue that your bundle can export the interfaces for the embedded jar as well, but this gets ugly since it should not be your bundles responsibility to expose that code. It also makes it easier to have multiple versions of the library exposed, or multiple providers of the same version.

2) This is Eclipse specific - The embedded jars don't resolve properly in the development environment (still works at runtime). My bundle may depend on a bundle in my target platform, and it will fail to resolve elements in the embedded jars, they have to be imported into the workspace to work.

I have found that most open source jars have already been kindly bundled by the nice folks at Spring. There are other repos available as well, but unfortunately I lost my links to them.

Perhaps you are looking for something like Maven? Not sure how that would work with OSGi though. You can find a little info on Jasper Reports with Maven here: http://mvnrepository.com/artifact/jasperreports/jasperreports

The Eclipse Orbit project has also made bundles from many commonly used third party jars.

http://www.eclipse.org/orbit/

To be specific about the questions you asked.

Everyone doesn't make their own. See my previous answer for a link to the Eclipse packaging of third party libraries as bundles. If you can't find and already packaged version, you'll have to make your own.

It is better to wrap binary dependencies in their own bundle than to include the jar as a binary into your code bundle. Pick whatever bundle name you want, its the package imports and exports that matter. Namespacing the bundle name with your project name will make sure you don't hit collisions.

Getting access to the bundle storage area for scanning isn't impossible, but it tends to require OSGi runtime specific information on how/where the bundles get extracted. So it's possible, but not easy.

spring has created osgi bundles of most of the open source libraries and i see jasper reports in there. check out their bundle repository @ http://www.springsource.com/repository/app/bundle

we have been using Maven with OSGI, we declare the bundle dependencies in its pom.xml and you don't have to worry about them anymore.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!