Howto:osgi 和共享包? [英] Howto: osgi and shared packages?

查看:26
本文介绍了Howto:osgi 和共享包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个应该使用 org.elasticsearch.client.RestHighLevelClient 的 osgi 应用程序.为此,我添加了包 servicemix.bundles.elasticsearch-client,因为它导出 org.elasticsearch.client 和所需的 RestHighLevelClient.显然,RestHighLevelClient 似乎需要 servicemix.bundles.elasticsearch(以及其他)才能工作,所以我也添加了它 - 两个版本相同.这两个包都导出 org.elasticsearch.client 但内容不同.一切都按预期加载,我可以验证导出的包.

编辑:我收到的问题是 org.elasticsearch.client.RestHighLevelClient 的 ClassNotFound 异常.这很奇怪,因为我可以看到 elasticsearch-client 可用并导出所需的包.

我的解释是 Karaf 似乎无法处理共享包.它似乎加载了具有所需包的包之一以满足我的应用程序功能的要求,然后决定即使所需的类实际上存在于另一个包中也足够了.

在@ChristianSchneider 发表评论并获得更多理解之后,我更新了我的配置.但是,问题仍然存在.

我现在有一个 elasticsearch-client6-feature 和一个 elasticsearch6-feature

<前><feature name="elasticsearch6" version="6.3.2" description="Elasticsearch Base libraries"><bundle start-level="80">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch/6.3.2_1</bundle><bundle dependency="true">mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-cbor/2.9.6</bundle><bundle dependency="true">mvn:com.fasterxml.jackson.core/jackson-core/2.9.6</bundle><bundle dependency="true">wrap:mvn:com.vividsolutions/jts/1.13</bundle><bundle dependency="true">wrap:mvn:io.sgr/s2-geometry-library-java/1.0.0</bundle><bundle dependency="true"><![CDATA[wrap:mvn:io.netty/netty-all/4.1.28.Final$Bundle-Version=4.1.28&Export-Package=*;version=4.1.28]]></bundle><bundle dependency="true">wrap:mvn:org.locationtech.jts/jts-core/1.15.1</bundle></功能><feature name="elasticsearch-client6" version="6.3.2" description="Elasticsearch Client libraries"><bundle start-level="80">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch-client/6.3.2_1</bundle></功能>

和我的应用程序功能

<前><功能名称="my-application" version="${version}"><bundle start-level="92">mvn:com.mycompany/application-feature/${version}</bundle></功能>

有人可以建议我如何强制我的应用程序功能同时加载 elasticsearch-client6-feature 和 elasticesearch6,因为它们都是必需的.

亲切的问候金克斯

解决方案

我遇到了同样的问题,这就是我所做的...

  1. 转到https://jar-download.com/artifacts/org.elasticsearch.client/elasticsearch-rest-high-level-client/all-versions 这是一个允许您下载 maven 工件及其所有依赖项的站点,选择您想要的版本.
  2. 选择版本后,单击红色下载按钮,它将下载一个包含所有弹性搜索 jar 和所需依赖项的 zip 文件.下载后,将 jar 解压缩到您的本地文件系统上.
  3. 创建一个类似 com.mycompany.thirdparty.elasticsearch 的包
  4. 在包的根目录中创建一个 lib 文件夹,并将您从下载中解压缩的所有 jar 复制/粘贴到该文件夹​​中.
  5. 使用 Eclipse MANIFEST 编辑器转到运行时选项卡,在类路径部分添加 lib 文件夹中的所有 jar.然后对于导出的包,单击添加并添加所有可用的包.

这将创建一个具有弹性搜索及其所有依赖项的包,这些包被导出到导入弹性搜索包或将该包添加为依赖项的其他包.

希望能让您朝着正确的方向前进,在 Eclipse 中使用 MANIFEST 编辑器最容易做到这一点,因为它会自动更新 build.properties 文件.

Im trying to write an osgi-application that should make use of the org.elasticsearch.client.RestHighLevelClient. For this I have added the bundle servicemix.bundles.elasticsearch-client since it exports org.elasticsearch.client with the needed RestHighLevelClient. Apparently though, it seems that the RestHighLevelClient needs servicemix.bundles.elasticsearch (amongst others) to work so I add that aswell - both of the same version. Both of the bundles export org.elasticsearch.client but with different content. Everything loads as expected and I can verify the exported packages.

EDIT: The problem that im getting reviels it self as a ClassNotFound-exception for org.elasticsearch.client.RestHighLevelClient. Which is odd since I can view that the elasticsearch-client is available and exporting the requred package.

My interpretation is that Karaf doesent seem to be able to handle shared packages. It seem to load one of the bundles that have the required package to suffice the requirement from my application-feature, and after that decides that it is enough even though the needed class actually exist in the the other bundle.

After comments from @ChristianSchneider and gaining some more understanding I have updated my configuration. However, the issue still remains.

I now have a elastisearch-client6-feature and an elasticsearch6-feature

   
    <feature name="elasticsearch6" version="6.3.2" description="Elasticsearch Base libraries">
        <bundle start-level="80">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch/6.3.2_1</bundle>
        <bundle dependency="true">mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-cbor/2.9.6</bundle>
        <bundle dependency="true">mvn:com.fasterxml.jackson.core/jackson-core/2.9.6</bundle>
        <bundle dependency="true">wrap:mvn:com.vividsolutions/jts/1.13</bundle>
        <bundle dependency="true">wrap:mvn:io.sgr/s2-geometry-library-java/1.0.0</bundle>
        <bundle dependency="true"><![CDATA[wrap:mvn:io.netty/netty-all/4.1.28.Final$Bundle-Version=4.1.28&Export-Package=*;version=4.1.28]]></bundle>
        <bundle dependency="true">wrap:mvn:org.locationtech.jts/jts-core/1.15.1</bundle>
    </feature>

    <feature name="elasticsearch-client6" version="6.3.2" description="Elasticsearch Client libraries">
        <bundle start-level="80">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch-client/6.3.2_1</bundle>
    </feature>

and my application-feature

    <feature name="my-application" version="${version}">
        <bundle start-level="92">mvn:com.mycompany/application-feature/${version}</bundle>
    </feature>

Can someone please suggest how I force my application-feature to both load the elasticsearch-client6-feature aswell as elasticesearch6 as they are both required.

Kind regards Jiinx

解决方案

I had the same problem and this is what I did...

  1. Go to https://jar-download.com/artifacts/org.elasticsearch.client/elasticsearch-rest-high-level-client/all-versions which is a site that lets you download maven artifacts as well as all their dependencies, select the version you want.
  2. After selecting the version click the red download button and it will download a zip file with all the elastic search jars and required dependencies.After downloading unzip the jar on your local file system.
  3. Create a bundle like com.mycompany.thirdparty.elasticsearch
  4. Create a lib folder in the root of the bundle and copy/paste all those jars you unzipped from the download into that folder.
  5. Using eclipse MANIFEST editor go to Runtime Tab, in the class path section add all the jars in the lib folder. Then for exported packages click add and add all the packages available.

This creates a bundle that has elastic search and all its dependencies which are exported to other bundles that import elastic search packages or add the bundle as a dependency.

Hope that gets you in the right direction, its easiest to do this in eclipse with the MANIFEST editor because it automatically updates build.properties files.

这篇关于Howto:osgi 和共享包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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