如何 OSGIfy 一个库 [英] How to OSGIfy a library

查看:21
本文介绍了如何 OSGIfy 一个库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,它是一个集成项目,我们正在使用 Apache Camel 和 Apache Karaf.在项目中,我需要使用Jira REST Java客户端库>

所以我已经阅读了很多关于如何将非 OSGI 库包装到 OSGI 包的各种文章和主题,但我真的不确定我是否做对了.

因此,我创建了一个依赖于所需库的 POM 文件.做了一个包,并尝试部署到Karaf,当然Karaf抱怨缺少包.

所以,我找到了对应的maven依赖,添加了它,包进入,依赖进入.

另一轮,部署,找到依赖项,添加,......一次又一次,直到 Karaf 对这个包满意.

真的是这样吗?在我看来这很疯狂,所以我想我没有像往常一样得到它:)

最后,我工作电脑上的包稳定了,我快速检查并回家,我继续,但奇怪的是,在我的个人电脑上编译的同一个POM/包不起作用,再次抱怨缺少包,但这一次,这个包肯定在 POM 文件中,并且肯定它嵌入在包中,我可以在那里看到它.

这次丢失的包是 org.apache.commons.codec.

org.osgi.framework.BundleException:bundle jiraclient.bundle [134] 中未解决的约束:无法解析 134.0:缺少需求 [134.0] osgi.wiring.package;(osgi.wiring.package=org.apache.commons.codec)在 org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826)[org.apache.felix.framework-4.0.3.jar:]在 org.apache.felix.framework.Felix.startBundle(Felix.java:1868)[org.apache.felix.framework-4.0.3.jar:]在 org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944)[org.apache.felix.framework-4.0.3.jar:]在 org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1247)[6:org.apache.felix.fileinstall:3.2.6]在 org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1219)[6:org.apache.felix.fileinstall:3.2.6]在 org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1208)[6:org.apache.felix.fileinstall:3.2.6]在 org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:503)[6:org.apache.felix.fileinstall:3.2.6]在 org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:291)[6:org.apache.felix.fileinstall:3.2.6]

所以,现在我完全糊涂了,怎么了:(

请大家帮帮我.谢谢!

POM 文件很长,所以我想链接更好:http://pastebin.com/j5cmWveG

解决方案

是的,恕我直言,OSGi 的部署模型远非易于使用",需要 100% 捆绑 MANIFEST.MF 文件中的 osgi 元数据.你需要数学博士学位才​​能理解 BND 工具.不幸的是,许多 JAR 不是 OSGi 包.

查看包含所有导入|导出的 pom.xml 文件,以及不容易理解"的语法,任何普通工程师只需 5 秒就可以理解丹麦写的东西"";例如 OSGi != 我们生活的世界.恕我直言,这必须而且应该更容易.

您可以使用 wrap url 处理程序在 Karaf 中安装一个普通的 JAR:http://karaf.apache.org/manual/latest/开发人员指南/creating-bundles.html

另一个技巧是创建一个超级 JAR,例如将它全部放在一个 JAR 文件中,然后您就可以部署它.

还有 FAB(Fuse Bundles)使 OSGi 部署更容易,因为它在部署时为您处理了很多这种疯狂的事情,而您不必处理 OSGi MANIFEST.MF 的疯狂: http://www.davsclaus.com/2012/08/osgi-deployment-made-easy-with-fab.html

I'm working on a project, it's integration project, we are using Apache Camel and Apache Karaf. In the project, I need to use the Jira REST Java client library.

So I've read quite a lot of various articles and threads about how to wrap non-OSGI library to OSGI bundle, but I'm really not sure if I got it right.

So, I've created a POM file with a dependency to the needed library. Made a package and tried to deploy it to Karaf, of course, Karaf complained for missing packages.

So, I've found corresponding maven dependency, added it, package goes into <Import-Package> and dependency into <Embed-Dependency>.

Another round, deploy, find dependency, add, ... and again, and again, until Karaf is fine with the bundle.

Is that really correct? It seems to me like quite crazy, so I guess I don't got it as usualy :)

Finally, the package get to stable that was on my work computer, I checked it quickly and went home, there I continued but, strange, the same POM / package, compiled on my personal computer is not working, again complaining about missing package, but this time, this package is for sure in the POM file and for sure it is embeded in the package, I can see it there.

This missing package is this time org.apache.commons.codec.

org.osgi.framework.BundleException: Unresolved constraint in bundle jiraclient.bundle [134]: Unable to     resolve 134.0: missing requirement [134.0] osgi.wiring.package; (osgi.wiring.package=org.apache.commons.codec)
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826)[org.apache.felix.framework-4.0.3.jar:]
    at org.apache.felix.framework.Felix.startBundle(Felix.java:1868)[org.apache.felix.framework-4.0.3.jar:]
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944)[org.apache.felix.framework-4.0.3.jar:]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1247)[6:org.apache.felix.fileinstall:3.2.6]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1219)[6:org.apache.felix.fileinstall:3.2.6]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1208)[6:org.apache.felix.fileinstall:3.2.6]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:503)[6:org.apache.felix.fileinstall:3.2.6]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:291)[6:org.apache.felix.fileinstall:3.2.6]

So, now I'm totally confused, what is wrong :(

Pretty please, guys, help me. Thanks!

The POM file is long, so I guess link is better: http://pastebin.com/j5cmWveG

解决方案

Yes OSGi is IMHO "far from easy to use" in terms of its deployment model, requiring 100% bundles with osgi metadata in MANIFEST.MF files. And you need a PhD in mathematics to understand the BND tool. And unfortunately many JARs are not OSGi bundles.

Looking at your pom.xml file with all the imports|exports, and that "not easy to understand" syntax, would just take 5-sec for any average engineer to understand that this "something is wrotten in the state of Denmark" ; eg OSGi != the world we live in. This must and should be easier IMHO.

You can install a plain JAR in Karaf using the wrap url handler: http://karaf.apache.org/manual/latest/developers-guide/creating-bundles.html

Another trick is to create an uber JAR, eg to put it all in a single JAR file and then you can deploy that.

There is also FAB (Fuse Bundles) which makes OSGi deployment easier, as it handles much of this craziness for you at deploy time, instead of you having to deal with the OSGi MANIFEST.MF madness: http://www.davsclaus.com/2012/08/osgi-deployment-made-easy-with-fab.html

这篇关于如何 OSGIfy 一个库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆