Howto: osgi and shared packages?

北战南征 提交于 2019-12-11 17:53:02

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/51790693/howto-osgi-and-shared-packages

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