Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Accessing native libraries from fragments using JNI(How to transform a bundleentry-URL to an absolute path)
Accessing native libraries from fragments using JNI [message #508852] Wed, 20 January 2010 14:53 Go to next message
M.  is currently offline M. Friend
Messages: 6
Registered: December 2009
Junior Member
Greetings,

I use JNI in a plugin project to access a native library. On my linux developer machine the native library is located on the library path and everything works fine.

Typically the application will be used on Windows machines without installed libraries, therefore I want to ship the required DLLs using a fragment plugin.

By using
Platform.getBundle().findEntries()
I can retrieve an URL to the file, wich is something like
bundleentry://115.fwk15354046/libcv200.dll


How can I transform this to an absolute file path which can be used by the JNI method Native.loadLibrary?
Re: Accessing native libraries from fragments using JNI [message #509149 is a reply to message #508852] Thu, 21 January 2010 14:11 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You can use Bundle-NativeCode to make DLLs available to your JNI through
OSGi. Google examples like:
Bundle-NativeCode: /lib/both.dll; /lib/xp.dll; osname=winxp;
processor=x86, /lib/both.dll; /lib/vista.dll; osname=winvista; processor=x86

But if you still want to be able to get access to your DLL (and this
works for any file in a plugin) you can use:
org.eclipse.core.runtime.FileLocator.toFileURL(URL)

Later,
PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Accessing native libraries from fragments using JNA [message #509601 is a reply to message #509149] Sat, 23 January 2010 14:00 Go to previous messageGo to next message
M.  is currently offline M. Friend
Messages: 6
Registered: December 2009
Junior Member
Thanks for your reply, unfortunately I included a big typing error in the topic title and question: I am using JNA, not JNI, sorry. Embarrassed

I guess Bundle-NativeCode doesn't work with JNA? The FileLocator should work though. I'll try it as soon as I am back in the office.
Re: Accessing native libraries from fragments using JNA [message #509816 is a reply to message #509601] Mon, 25 January 2010 14:12 Go to previous messageGo to next message
M.  is currently offline M. Friend
Messages: 6
Registered: December 2009
Junior Member
I did some tests now, using the FileLocator works like a charm while using the development environment.

Unfortunately after exporting the product, it does not. I am positively surprised that eclipse automatically extracts the accessed files to something like
<product directory>\configuration\org.eclipse.osgi\bundles\38\1\.cp\libcvaux200.dll

but JNA complains that it can not find the DLLs.

I'll try to find out where the problem is, the path seems correct, at least I can copy it from the error message and paste it to the windows explorer and it can access the directory.
Re: Accessing native libraries from fragments using JNA [message #509916 is a reply to message #509816] Mon, 25 January 2010 18:46 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

M. wrote:
> Unfortunately after exporting the product, it does not. I am positively
> surprised that eclipse automatically extracts the accessed files to
> something like
> <product
> directory> \configuration\org.eclipse.osgi\bundles\38\1\.cp\libcvaux200 .dll
> but JNA complains that it can not find the DLLs.

It's unfortunate that JNA can't "see" the DLLs. Maybe it expects
they're part of a lib or execution path?

as for extracting, that's what FileLocator offers ... if the plugin is a
directory plugin, it will simply reference the file. If the plugin is a
jar plugin it will extract the file so it can be referenced.

Later,
PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Accessing native libraries from fragments using JNA [message #510077 is a reply to message #509916] Tue, 26 January 2010 13:34 Go to previous message
M.  is currently offline M. Friend
Messages: 6
Registered: December 2009
Junior Member
I solved it now by using the FileLocator to get access to the DLL and then copying it to the directory of the executable.

Thanks a lot,
M.
Previous Topic:Activities based on source variables
Next Topic:How to open a plugin resource inside the WebBrowser editor
Goto Forum:
  


Current Time: Sat Apr 20 02:15:25 GMT 2024

Powered by FUDForum. Page generated in 0.03330 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top