Just to clarify: There are two options to deal with native code. 

The one is the "OSGi way" of doing it, this is embedding the shared library 
into the bundle and using Bundle-NativeCode to make the library available. This 
is the preferred way since then the native code is under proper lifecycle 
management and the Bundle-NativeCode is a very powerful facility for supporting 
multiple platforms.

If this is not an option, then you have to fall back to the standard Java way 
of dealing with native code, which is a scan through java.library.path (which 
is by default LD_LIBRARY_PATH on *nix). Even though implementation of OSGi 
frameworks typically override findLibrary in their bundle, the code path taken 
by calling System.loadLibrary will call loadLibrary0 directly if findLibrary 
previously returned null. 

What could happen though is that your framework implements findLibrary in such 
a way that it directly throws an UnsatisfiedLinkError, e.g., when you try to 
load a library and you have no Bundle-NativeCode directive in your manifest. In 
this case, you have an immediate failure and there is no fall back. I can't see 
anything in the specs that prevent frameworks from doing so. As a consequence, 
you would not be able to call System.loadLibrary from within a bundle to load 
libraries outside of the bundle.

Cheers, 

Jan.


------------------------------------------------------------
MSc Jan S. Rellermeyer
Systems Group, Department of Computer Science, ETH Zurich 
CAB E 78, Universitaetstrasse 6, CH-8092 Zürich, Switzerland
http://www.systems.ethz.ch
------------------------------------------------------------ 

 

-----Original Message-----
From: [email protected] [mailto:[email protected]] On 
Behalf Of Christopher Armstrong
Sent: Dienstag, 27. April 2010 04:32
To: OSGi Developer Mail List
Subject: Re: [osgi-dev] loading native code outside of the bundle


On 27/04/2010, at 11:47 AM, Ikuo Yamasaki wrote:

> BJ> Did you try this out?
>
> Yes and I succeeded in loading the code.
>
> However, from the OSGi Spec point of view,
> I cannot find whether it is proper way.
> (This might be not OSGi issue but System.loadLibrary issue.)
>
> That's why I asked.


As far as I can tell from reading the OSGi specification, there is no  
other way, and this is the method I use in my own code. The OSGi  
framework you're using should have installed a custom classloader that  
will be used to locate the shared library using the Bundle-NativeCode  
header, so all ought to be fine.

Cheers
Chris
--------
Christopher Armstrong
[email protected]





_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to