You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Davi Baldin Tavares <da...@gmail.com> on 2020/05/09 17:30:32 UTC

Possible issue with ServiceLoader.load() inside bundle

Hi Karaf users,

My bundle is using Elasticsearch 7.x. jars and everything is almost working well, except for internal classes not being constructed well. Code is working no tests outside Karaf.

While investigating, I’ve found this piece of code

XContentBuilder.class:117 (Elastic)

 // Load pluggable extensions
        for (XContentBuilderExtension service : ServiceLoader.load(XContentBuilderExtension.class)) {
            Map<Class<?>, Writer> addlWriters = service.getXContentWriters();  

Jar file has META-INF/services file for XContentBuilderExtension (the piece of code that is not being resolved while using Karaf). I’m using 4.2.7

Unfortunately, Elasting isn’t OSGi ready either (no Bundle META):

karaf@root()> bundle:install -s mvn:org.elasticsearch/elasticsearch/7.6.2
Bundle IDs: 
Error executing command: Error installing bundles:
	Unable to install bundle mvn:org.elasticsearch/elasticsearch/7.6.2: org.osgi.framework.BundleException: OSGi R3 bundle not supported
karaf@root()> bundle:install -s mvn:org.elasticsearch.client/elasticsearch-rest-high-level-client/7.6.2
Bundle IDs: 
Error executing command: Error installing bundles:
	Unable to install bundle mvn:org.elasticsearch.client/elasticsearch-rest-high-level-client/7.6.2: org.osgi.framework.BundleException: OSGi R3 bundle not supported


Is there a way to make sure ServiceLoader is able to work with JARs inside bundle’s class path?

Thanks,

Davi

Re: Possible issue with ServiceLoader.load() inside bundle

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
That’s probably because SPI load implementation from other artifacts.

Regards
JB

> Le 11 mai 2020 à 13:46, Davi Baldin Tavares <da...@gmail.com> a écrit :
> 
> JB,
> 
> After reading of Apache Aires’s Service API 10 times I could figured out:
> 
> a) maven-bundle-plugin changes
> 
> <SPI-Consumer>*</SPI-Consumer>
> <Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</Require-Capability>
> <Import-Package>.,
> Path/to/merged-elastic-jars
> …
> 
> b) Merge all Elastic’s JARs files into a single one... 
> <target name="zip">
>         <zip destfile="elasticsearch-all-7.6.2.jar">
>             <zipgroupfileset dir="." includes="*7.6.2*.jar"/>
>         </zip>
>         <zip destfile="lucene-all-8.4.0.jar">
>             <zipgroupfileset dir="." includes="*8.4.0*.jar"/>
>         </zip>
>     </target>
> 
> I really didn’t get why merging jar into single one was part of the solution, but it is fine to me.
> 
> Thanks,
> 
> Davi
> 
> 
>> On 10 May 2020, at 02:44, Jean-Baptiste Onofré <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
>> 
>> Hi
>> 
>> Do you embed meta-in fin your bundle ? You can take a look on elasticsearch 7.x service mix bundle  
>> 
>> Regards 
>> JB
>> 
>> Le sam. 9 mai 2020 ? 19:30, Davi Baldin Tavares <davi.baldin@gmail.com <ma...@gmail.com>> a ?crit :
>> Hi Karaf users,
>> 
>> My bundle is using Elasticsearch 7.x. jars and everything is almost working well, except for internal classes not being constructed well. Code is working no tests outside Karaf.
>> 
>> While investigating, I?ve found this piece of code
>> 
>> XContentBuilder.class:117 (Elastic)
>> 
>>  // Load pluggable extensions
>>         for (XContentBuilderExtension service : ServiceLoader.load(XContentBuilderExtension.class)) {
>>             Map<Class<?>, Writer> addlWriters = service.getXContentWriters();  
>> 
>> Jar file has META-INF/services file for XContentBuilderExtension (the piece of code that is not being resolved while using Karaf). I?m using 4.2.7
>> 
>> Unfortunately, Elasting isn?t OSGi ready either (no Bundle META):
>> 
>> karaf@root()> bundle:install -s mvn:org.elasticsearch/elasticsearch/7.6.2
>> Bundle IDs: 
>> Error executing command: Error installing bundles:
>> 	Unable to install bundle mvn:org.elasticsearch/elasticsearch/7.6.2: org.osgi.framework.BundleException: OSGi R3 bundle not supported
>> karaf@root()> bundle:install -s mvn:org.elasticsearch.client/elasticsearch-rest-high-level-client/7.6.2
>> Bundle IDs: 
>> Error executing command: Error installing bundles:
>> 	Unable to install bundle mvn:org.elasticsearch.client/elasticsearch-rest-high-level-client/7.6.2: org.osgi.framework.BundleException: OSGi R3 bundle not supported
>> 
>> 
>> Is there a way to make sure ServiceLoader is able to work with JARs inside bundle?s class path?
>> 
>> Thanks,
>> 
>> Davi
> 


Re: Possible issue with ServiceLoader.load() inside bundle

Posted by Davi Baldin Tavares <da...@gmail.com>.
JB,

After reading of Apache Aires’s Service API 10 times I could figured out:

a) maven-bundle-plugin changes

<SPI-Consumer>*</SPI-Consumer>
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</Require-Capability>
<Import-Package>.,
Path/to/merged-elastic-jars
…

b) Merge all Elastic’s JARs files into a single one... 
<target name="zip">
        <zip destfile="elasticsearch-all-7.6.2.jar">
            <zipgroupfileset dir="." includes="*7.6.2*.jar"/>
        </zip>
        <zip destfile="lucene-all-8.4.0.jar">
            <zipgroupfileset dir="." includes="*8.4.0*.jar"/>
        </zip>
    </target>

I really didn’t get why merging jar into single one was part of the solution, but it is fine to me.

Thanks,

Davi


> On 10 May 2020, at 02:44, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
> 
> Hi
> 
> Do you embed meta-in fin your bundle ? You can take a look on elasticsearch 7.x service mix bundle  
> 
> Regards 
> JB
> 
> Le sam. 9 mai 2020 ? 19:30, Davi Baldin Tavares <da...@gmail.com> a ?crit :
> Hi Karaf users,
> 
> My bundle is using Elasticsearch 7.x. jars and everything is almost working well, except for internal classes not being constructed well. Code is working no tests outside Karaf.
> 
> While investigating, I?ve found this piece of code
> 
> XContentBuilder.class:117 (Elastic)
> 
>  // Load pluggable extensions
>         for (XContentBuilderExtension service : ServiceLoader.load(XContentBuilderExtension.class)) {
>             Map<Class<?>, Writer> addlWriters = service.getXContentWriters();  
> 
> Jar file has META-INF/services file for XContentBuilderExtension (the piece of code that is not being resolved while using Karaf). I?m using 4.2.7
> 
> Unfortunately, Elasting isn?t OSGi ready either (no Bundle META):
> 
> karaf@root()> bundle:install -s mvn:org.elasticsearch/elasticsearch/7.6.2
> Bundle IDs: 
> Error executing command: Error installing bundles:
> 	Unable to install bundle mvn:org.elasticsearch/elasticsearch/7.6.2: org.osgi.framework.BundleException: OSGi R3 bundle not supported
> karaf@root()> bundle:install -s mvn:org.elasticsearch.client/elasticsearch-rest-high-level-client/7.6.2
> Bundle IDs: 
> Error executing command: Error installing bundles:
> 	Unable to install bundle mvn:org.elasticsearch.client/elasticsearch-rest-high-level-client/7.6.2: org.osgi.framework.BundleException: OSGi R3 bundle not supported
> 
> 
> Is there a way to make sure ServiceLoader is able to work with JARs inside bundle?s class path?
> 
> Thanks,
> 
> Davi


Re: Possible issue with ServiceLoader.load() inside bundle

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi

  

Do you embed meta-in fin your bundle ? You can take a look on elasticsearch
7.x service mix bundle  

  

Regards

JB

  

Le sam. 9 mai 2020 ? 19:30, Davi Baldin Tavares <da...@gmail.com> a
?crit :  

> Hi Karaf users,

>

>  
>

>

> My bundle is using Elasticsearch 7.x. jars and everything is almost working
well, except for internal classes not being constructed well. Code is working
no tests outside Karaf.

>

>  
>

>

> While investigating, I?ve found this piece of code

>

>  
>

>

> XContentBuilder.class:117 (Elastic)

>

>  
>

>

>  // Load pluggable extensions

>

>         **for** (XContentBuilderExtension service :
ServiceLoader.load(XContentBuilderExtension. **class** )) {

>

>             Map<Class<?>, Writer> addlWriters =
service.getXContentWriters();  
>

>  
>

>

> Jar file has META-INF/services file for XContentBuilderExtension (the piece
of code that is not being resolved while using Karaf). I?m using 4.2.7

>

>  
>

>

> Unfortunately, Elasting isn?t OSGi ready either (no Bundle META):

>

>  
>

>

> karaf@root()> bundle:install -s mvn:org.elasticsearch/elasticsearch/7.6.2

>

> Bundle IDs:

>

> Error executing command: Error installing bundles:

>

> Unable to install bundle mvn:org.elasticsearch/elasticsearch/7.6.2:
org.osgi.framework.BundleException: OSGi R3 bundle not supported

>

> karaf@root()> bundle:install -s mvn:org.elasticsearch.client/elasticsearch-
rest-high-level-client/7.6.2

>

> Bundle IDs:

>

> Error executing command: Error installing bundles:

>

> Unable to install bundle mvn:org.elasticsearch.client/elasticsearch-rest-
high-level-client/7.6.2: org.osgi.framework.BundleException: OSGi R3 bundle
not supported

>

>  
>

>

>  
>

>

> Is there a way to make sure ServiceLoader is able to work with JARs inside
bundle?s class path?

>

>  
>

>

> Thanks,

>

>  
>

>

> Davi