You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Robert A. Decker" <de...@robdecker.com> on 2012/07/22 20:58:46 UTC

native library in bundle

Hi,

I have a jar that has a native c++ library as part of it:

            <dependency>
                <groupId>org.zeromq</groupId>
                <artifactId>jzmq-bmndev</artifactId>
                <version>1.0.0</version>
                <scope>compile</scope>
            </dependency>

It was working fairly well for awhile. I'd have to restart the app during my builds every now and then because it wouldn't be able to load the native library, but not too often.

However, lately it's just gone to hell. I now have to restart every build. I'm not sure what changed.

Here's the error:

22.07.2012 18:36:53.323 *ERROR* [FelixPackageAdmin] bmn-core [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl] The activate method has thrown an exception (java.lang.UnsatisfiedLinkError: Native Library /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader) java.lang.UnsatisfiedLinkError: Native Library /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader

And then when you try to start the component manually in the sling console:

22.07.2012 18:48:25.567 *ERROR* [814353636@qtp-575823446-4] bmn-core [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl] The activate method has thrown an exception (java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ) java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ at org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl.activate(DivisiWrapperServiceImpl.java:45)


Is there something I can do so that the class loaders don't have this problem?

Rob

Re: native library in bundle

Posted by "Robert A. Decker" <de...@robdecker.com>.
Hi Felix,

That's exactly what we did. We now only build the native bundle when necessary.

Rob

On Nov 2, 2012, at 4:58 PM, Felix Meschberger wrote:

> Hi Rob
> 
> Sorry for the late response. This question was burried deep down in my dring-PTO-messages.
> 
> I am not too familiar with native code in OSGi frameworks. You might want to ask these questions on the Felix Users List.
> 
> One point: I think it would be good to isolate the native code in a separate bundle an expose its access through an OSGi service.
> 
> Regards
> Felix
> 
> Am 22.07.2012 um 20:58 schrieb Robert A. Decker:
> 
>> Hi,
>> 
>> I have a jar that has a native c++ library as part of it:
>> 
>>           <dependency>
>>               <groupId>org.zeromq</groupId>
>>               <artifactId>jzmq-bmndev</artifactId>
>>               <version>1.0.0</version>
>>               <scope>compile</scope>
>>           </dependency>
>> 
>> It was working fairly well for awhile. I'd have to restart the app during my builds every now and then because it wouldn't be able to load the native library, but not too often.
>> 
>> However, lately it's just gone to hell. I now have to restart every build. I'm not sure what changed.
>> 
>> Here's the error:
>> 
>> 22.07.2012 18:36:53.323 *ERROR* [FelixPackageAdmin] bmn-core [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl] The activate method has thrown an exception (java.lang.UnsatisfiedLinkError: Native Library /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader) java.lang.UnsatisfiedLinkError: Native Library /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader
>> 
>> And then when you try to start the component manually in the sling console:
>> 
>> 22.07.2012 18:48:25.567 *ERROR* [814353636@qtp-575823446-4] bmn-core [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl] The activate method has thrown an exception (java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ) java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ at org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl.activate(DivisiWrapperServiceImpl.java:45)
>> 
>> 
>> Is there something I can do so that the class loaders don't have this problem?
>> 
>> Rob
> 
> 


Re: native library in bundle

Posted by Felix Meschberger <fm...@adobe.com>.
Hi Rob

Sorry for the late response. This question was burried deep down in my dring-PTO-messages.

I am not too familiar with native code in OSGi frameworks. You might want to ask these questions on the Felix Users List.

One point: I think it would be good to isolate the native code in a separate bundle an expose its access through an OSGi service.

Regards
Felix

Am 22.07.2012 um 20:58 schrieb Robert A. Decker:

> Hi,
> 
> I have a jar that has a native c++ library as part of it:
> 
>            <dependency>
>                <groupId>org.zeromq</groupId>
>                <artifactId>jzmq-bmndev</artifactId>
>                <version>1.0.0</version>
>                <scope>compile</scope>
>            </dependency>
> 
> It was working fairly well for awhile. I'd have to restart the app during my builds every now and then because it wouldn't be able to load the native library, but not too often.
> 
> However, lately it's just gone to hell. I now have to restart every build. I'm not sure what changed.
> 
> Here's the error:
> 
> 22.07.2012 18:36:53.323 *ERROR* [FelixPackageAdmin] bmn-core [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl] The activate method has thrown an exception (java.lang.UnsatisfiedLinkError: Native Library /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader) java.lang.UnsatisfiedLinkError: Native Library /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader
> 
> And then when you try to start the component manually in the sling console:
> 
> 22.07.2012 18:48:25.567 *ERROR* [814353636@qtp-575823446-4] bmn-core [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl] The activate method has thrown an exception (java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ) java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ at org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl.activate(DivisiWrapperServiceImpl.java:45)
> 
> 
> Is there something I can do so that the class loaders don't have this problem?
> 
> Rob


Re: native library in bundle

Posted by "Robert A. Decker" <de...@robdecker.com>.
The native code is under /usr/local

Then there is a java wrapper that is loaded as a dependency through maven with the scope 'compile'. The wrapper was built and linked on the server and then put into our archiva server. Both of these libraries are just the standard zeromq libraries, and so it's possible that the java wrapper isn't ready for OSGi. 

It's the zeromq library, in case anyone already has experience with it.

I don't want to spend too much time on this though, because we will switch to RabbitMQ for our messaging framework.

Rob

On Nov 4, 2012, at 8:11 PM, Karl Pauls wrote:

> This looks like you are not using osgi mechanisms to load the native
> library but do it some other way - right (and if so, why :-)?
> 
> regards,
> 
> Karl
> 
> 
> On Sun, Jul 22, 2012 at 8:58 PM, Robert A. Decker <de...@robdecker.com>wrote:
> 
>> Hi,
>> 
>> I have a jar that has a native c++ library as part of it:
>> 
>>            <dependency>
>>                <groupId>org.zeromq</groupId>
>>                <artifactId>jzmq-bmndev</artifactId>
>>                <version>1.0.0</version>
>>                <scope>compile</scope>
>>            </dependency>
>> 
>> It was working fairly well for awhile. I'd have to restart the app during
>> my builds every now and then because it wouldn't be able to load the native
>> library, but not too often.
>> 
>> However, lately it's just gone to hell. I now have to restart every build.
>> I'm not sure what changed.
>> 
>> Here's the error:
>> 
>> 22.07.2012 18:36:53.323 *ERROR* [FelixPackageAdmin] bmn-core
>> [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl]
>> The activate method has thrown an exception
>> (java.lang.UnsatisfiedLinkError: Native Library
>> /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader)
>> java.lang.UnsatisfiedLinkError: Native Library
>> /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader
>> 
>> And then when you try to start the component manually in the sling console:
>> 
>> 22.07.2012 18:48:25.567 *ERROR* [814353636@qtp-575823446-4] bmn-core
>> [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl]
>> The activate method has thrown an exception
>> (java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ)
>> java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ
>> at
>> org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl.activate(DivisiWrapperServiceImpl.java:45)
>> 
>> 
>> Is there something I can do so that the class loaders don't have this
>> problem?
>> 
>> Rob
> 
> 
> 
> 
> -- 
> Karl Pauls
> karlpauls@gmail.com
> http://twitter.com/karlpauls
> http://www.linkedin.com/in/karlpauls
> https://profiles.google.com/karlpauls


Re: native library in bundle

Posted by Karl Pauls <ka...@gmail.com>.
This looks like you are not using osgi mechanisms to load the native
library but do it some other way - right (and if so, why :-)?

regards,

Karl


On Sun, Jul 22, 2012 at 8:58 PM, Robert A. Decker <de...@robdecker.com>wrote:

> Hi,
>
> I have a jar that has a native c++ library as part of it:
>
>             <dependency>
>                 <groupId>org.zeromq</groupId>
>                 <artifactId>jzmq-bmndev</artifactId>
>                 <version>1.0.0</version>
>                 <scope>compile</scope>
>             </dependency>
>
> It was working fairly well for awhile. I'd have to restart the app during
> my builds every now and then because it wouldn't be able to load the native
> library, but not too often.
>
> However, lately it's just gone to hell. I now have to restart every build.
> I'm not sure what changed.
>
> Here's the error:
>
> 22.07.2012 18:36:53.323 *ERROR* [FelixPackageAdmin] bmn-core
> [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl]
> The activate method has thrown an exception
> (java.lang.UnsatisfiedLinkError: Native Library
> /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader)
> java.lang.UnsatisfiedLinkError: Native Library
> /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader
>
> And then when you try to start the component manually in the sling console:
>
> 22.07.2012 18:48:25.567 *ERROR* [814353636@qtp-575823446-4] bmn-core
> [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl]
> The activate method has thrown an exception
> (java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ)
> java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ
> at
> org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl.activate(DivisiWrapperServiceImpl.java:45)
>
>
> Is there something I can do so that the class loaders don't have this
> problem?
>
> Rob




-- 
Karl Pauls
karlpauls@gmail.com
http://twitter.com/karlpauls
http://www.linkedin.com/in/karlpauls
https://profiles.google.com/karlpauls

Re: native library in bundle

Posted by "Robert A. Decker" <de...@robdecker.com>.
One way I'm thinking about getting around it is creating a new maven module 'bmn-native' and put this service (and any other in the future that may require native code), and don't include that module in the normal dev build process.

It's a hack but I think should work.

Is anyone else using native code in a jar?

Rob

On Jul 22, 2012, at 2:58 PM, Robert A. Decker wrote:

> Hi,
> 
> I have a jar that has a native c++ library as part of it:
> 
>            <dependency>
>                <groupId>org.zeromq</groupId>
>                <artifactId>jzmq-bmndev</artifactId>
>                <version>1.0.0</version>
>                <scope>compile</scope>
>            </dependency>
> 
> It was working fairly well for awhile. I'd have to restart the app during my builds every now and then because it wouldn't be able to load the native library, but not too often.
> 
> However, lately it's just gone to hell. I now have to restart every build. I'm not sure what changed.
> 
> Here's the error:
> 
> 22.07.2012 18:36:53.323 *ERROR* [FelixPackageAdmin] bmn-core [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl] The activate method has thrown an exception (java.lang.UnsatisfiedLinkError: Native Library /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader) java.lang.UnsatisfiedLinkError: Native Library /usr/local/lib/libjzmq.so.0.0.0 already loaded in another classloader
> 
> And then when you try to start the component manually in the sling console:
> 
> 22.07.2012 18:48:25.567 *ERROR* [814353636@qtp-575823446-4] bmn-core [org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl] The activate method has thrown an exception (java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ) java.lang.NoClassDefFoundError: Could not initialize class org.zeromq.ZMQ at org.brainsciences.bmn.commons.core.services.impl.DivisiWrapperServiceImpl.activate(DivisiWrapperServiceImpl.java:45)
> 
> 
> Is there something I can do so that the class loaders don't have this problem?
> 
> Rob