Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » RCP and JNI lib
RCP and JNI lib [message #446507] Tue, 21 March 2006 13:58 Go to next message
Eclipse UserFriend
Originally posted by: b.h.stud.uni-goettingen.de

Hello,

I have a question about RCP and JNI.

I want to call a JNI from my RCP Application. My JNI works with a normal
Java Application without problems. Now I want to use this JNI with my new
RCP Application. But it doesn't work.
When I try to get access to the JNI, I get this error:

Unhandled event loop exception
Reason:
javaCanSocketCreate


JavaCanSocketCreate is a Methode in my JNI.


Best regards

Björn
Re: RCP and JNI lib [message #446511 is a reply to message #446507] Tue, 21 March 2006 14:43 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
This is yet again one of those unhelpful exceptions where the loop is printing out just the exception's message, and not its type. The actual exception is an UnsatisfiedLinkError, and it means that it can't load your DLL for your native code to work.

Are you bundling the DLL with your plugin? When you export your plugin, can you open it up and see the DLL in there? You can't put a native piece of code into a Jar and then put the Jar into a plugin; you've got to have the DLL individually available in the root of the plugin for it to work. It should look like:

org.example.plugin/
+ example.dll
+ yourcode.jar

(or the Jar can be unpacked)

Alex
Re: RCP and JNI lib [message #446520 is a reply to message #446507] Tue, 21 March 2006 17:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jean-philippe.shields.nurun.com

I had a similar problem some time ago. Te solution was that my normal
java application didn't had a package anem but my RCP application had
one. Your JNI function declaration must also have the package name
before your class name. Adding it resolved my problem.


b.h@stud.uni-goettingen.de (=?iso-8859-15?Q?Bj=F6rn?=) wrote in
news:f8f57133a6d3b59da9d5f5f1a214b17a$1@www.eclipse.org:

> Hello,
>
> I have a question about RCP and JNI.
>
> I want to call a JNI from my RCP Application. My JNI works with a
> normal Java Application without problems. Now I want to use this JNI
> with my new RCP Application. But it doesn't work.
> When I try to get access to the JNI, I get this error:
>
> Unhandled event loop exception
> Reason:
> javaCanSocketCreate
>
>
> JavaCanSocketCreate is a Methode in my JNI.
>
>
> Best regards
>
> Bj
Re: RCP and JNI lib [message #446644 is a reply to message #446520] Wed, 22 March 2006 16:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: b.h.stud.uni-goettingen.de

At first, thank you for help!!

I am sorry to say that doesn't work. I have generate with Eclipse a
RCP-Application. After that I put the JNI Java File (this file had the
nativ calls an the system.load.library call) in to the package from my RCP
Application. Then I put the *.so File in the root directory from my RCP
Application. Now when I compile the Projekt it works. The problems come
with the first call to *.so File.
Where is the mistake? My simple Java Application didn't have a package.
Now in the new Application, I have put the package name in the JNI Java
File, but i don't have generate the *.so new.
When I make a package in my simple Java Application I think I make a
mistake, because the simple Java Application doesn't work.
What can I do to make it that it works? Sorry for my very bad english, but
I hope you can understand me.

Best regards

Björn
Re: RCP and JNI lib [message #446646 is a reply to message #446644] Wed, 22 March 2006 17:32 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Like Alex said you should be creating an RCP app that looks something like:

rcp/
features/
plugins/
main.rcp.plugin

main.rcp.plugin can either be a directory itself or a jar. If you just
create a plugin from the examples (with a default bundle classpath of
..), when you export it you'll end up with a structure of:

main.rcp.plugin
com/ # all of your class files, including your JNI java stuff
META-INF/ # your manifest
plugin.xml # and maybe a properties file, etc
mylib.dll

The only other thing I can think of is you can specify native library
locations using a OSGi header in the plugin manifest file.

Later,
PW


Re: RCP and JNI lib [message #446648 is a reply to message #446646] Wed, 22 March 2006 19:38 Go to previous messageGo to next message
Stepan Rutz is currently offline Stepan RutzFriend
Messages: 52
Registered: July 2009
Member
Hi,

i am using the following layout

pluginrootdir/
nativelibs/

and the following line in the manifest.mf
(modified example line)

Bundle-NativeCode: nativelibs/libforwindows.dll;
nativelibs/anotherlibforwindows.dll;
osname=win32;
osname=Windows95;
osname=Windows98;
osname=WindowsNT;
osname=WindowsXP;
processor=x86,
nativelibs/libforlinux.so;
osname=Linux; processor=x86

This is not exactly how I do it, but similar.

OSGI then takes care of the magic. Upon start if will unpack the plugin
into the configuration directory and put the native libs there and
dispatches the lookup to find them there. This is perfect for me and
allows me to use OSGI to dispatch to different operating systems.

Infact I maintain different versions of the libs so I do have several
directories like

nativelibs1/
nativelibs2/
nativelibs3/

and i can just change by means of the manifest.mf (though i havent found a
way to do that dynamically yet).


Hope this extra info helps.

/Stepan
Re: RCP and JNI lib [message #446650 is a reply to message #446648] Wed, 22 March 2006 19:42 Go to previous messageGo to next message
Stepan Rutz is currently offline Stepan RutzFriend
Messages: 52
Registered: July 2009
Member
I just wanted to express my gratitude. OSGI's ability to dispatch the
native libs is just outstanding, awesome, great, I love it!!!

Sorry for getting carried away here.

Regards,
Stepan
Re: RCP and JNI lib [message #446668 is a reply to message #446648] Thu, 23 March 2006 09:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: b.h.stud.uni-goettingen.de

Hello,

thanks for the introduction, but I don't unterstand. I have following
folder structur.

(Projektname is "Versuch")

Versuch/
-src/
versuch/ (package)
Application.java
ApplicationActionBarAdvisor.java
....
Perspective.java
jllcf.java

-jllcf/
libjllcflib.so

-META-INF/
MANIFEST.MF

-plugin.properites
-plugin.xml
-....
-versuch.product

I copied the jllcf.java from my old simple Java application in to the
folder /src/versuch/ in my new RCP application. After that I generate a
new folder jllcf in the Projekt folder an copied the libjllcflib.so from
my old applicaton in to this folder. And then I have modified the
MANIFEST.MF


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Versuch Plug-in
Bundle-SymbolicName: Versuch; singleton:=true
Bundle-Version: 1.0.0
Bundle-ClassPath: versuch.jar
Bundle-Activator: versuch.VersuchPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.forms
Bundle-NativeCode:
jllcflib/libjllcflib.so;
osname=Linux; processor=x86
Eclipse-AutoStart: true


But it doesn't work. I started with RCP and Eclipe for two weeks. Before I
build simple Java application with the JBuilder. Whats wrong with my
application? What have I forgotten or make wrong.
Re: RCP and JNI lib [message #446674 is a reply to message #446668] Thu, 23 March 2006 12:42 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Björn wrote:
>
> I copied the jllcf.java from my old simple Java application in to the
> folder /src/versuch/ in my new RCP application. After that I generate a
> new folder jllcf in the Projekt folder an copied the libjllcflib.so from
> my old applicaton in to this folder. And then I have modified the
> MANIFEST.MF

First of all, did you update your jllcf.java file to be in the versuch
package? Then regenerate your JNI headers and re-compile your
libjllcflib.so native lib?

> Bundle-NativeCode: jllcflib/libjllcflib.so;
> osname=Linux; processor=x86
> Eclipse-AutoStart: true

Second, you said you created a jllcf folder but you've listed jllcflib
folder here? Just a transcribe error?


Third, does the directory structure of the exported plugin look like
what Stepan and I have mentioned? It's the deployed one that will matter.

Later,
PW


Re: RCP and JNI lib [message #446759 is a reply to message #446674] Thu, 23 March 2006 13:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: b.h.stud.uni-goettingen.de

Thank you that trying to help me!!!!

Ok, now I have generate a new header file from the jllcf.java file with
the package. Then I build a new C File. After that I generate a new *.so
file. This file copied in the jllcflib folder (it was here a typing
mistake).
Now I exported the Projekt. Till now I was thinking you mean the folder
structure in Eclipse :-( Sorry!!

Eclipse generate fowlling folder structur by export


plugins/
Versuch_1.0.0/
jllcflib/
libjllcflib.so

META-INF/
MANIFEST.MF

plugin.xml
versuch.jar

(In versuch.jar are all *.class files included)

At first the jllcflib folder was not exported, but after that I selected
it in Eclipse and now I have this folder structure. But it still doesn't
work. Why you want see the folder structure from the plugin export? And
now ??? :-(


Gruß

Björn
Re: RCP and JNI lib [message #446784 is a reply to message #446759] Fri, 24 March 2006 10:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: b.h.stud.uni-goettingen.de

Hello,

I have found the mistake!

Tanks a lot at all people that help me !!!!


Best regards

Björn
Re: RCP and JNI lib [message #446785 is a reply to message #446784] Fri, 24 March 2006 10:24 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
Would be nice to let the people know what it was so others who view this
thread know the solution.

Björn wrote:
> Hello,
>
> I have found the mistake!
>
> Tanks a lot at all people that help me !!!!
>
>
> Best regards
>
> Björn
>
Re: RCP and JNI lib [message #446789 is a reply to message #446785] Fri, 24 March 2006 11:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: b.h.stud.uni-goettinge.de

The main problem was that I have no package in my JNI Java File. I have
then put the JNI Java file in an package. I generate a new header,
c-source an *.so file. The Problem was I copied the source from the old
C-File (without a package) and modified only the methods like in the new
header File. Actually no problem, but there must be any thing wrong by the
copy and paste. Now I have copied the new delcaration from the new header
file in to a new C File. The lines in the source code from the dont't
working C File and my new C-File are absolut the same. I don't now were
the mistake is. I only know it was a very silly mistake.

Steps to integrate a own JNI LIB to RCP Application:

1. Put your JNI Java File in to the Application.
2. Generate with javah your header file.
3. Build the C-File an generate the *.so or *.dll file
3. Create a new Folder in your Projekt and put the *.so file in there.
4. Modified your MANIFEST.MF

I think that's it.
Re: RCP and JNI lib [message #446793 is a reply to message #446789] Fri, 24 March 2006 13:06 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Woo Woo!

PW


Re: RCP and JNI lib [message #461627 is a reply to message #446648] Sun, 14 January 2007 16:28 Go to previous message
David is currently offline DavidFriend
Messages: 47
Registered: July 2009
Member
I tried packaging a JNI project into a plugin and had some problems with
link errors at the beginning. I discovered a few things that were not
obvious from the posts I was reading:

- Making an entry in the Manifest.mf using "Bundle-NativeCode:" was
necessary. Otherwise the dlls were not being found.
- It seemed necessary to include the processor and osname elements when
describing the Bundle-NativeCode. When I left them out, the RCP app would
not start and an exception was thrown "org.osgi.framework.BundleException:
No Bundle-NativeCode match"
- So in the end it looked like this
Bundle-NativeCode: environment/c.dll; environment/b.dll;
environment/a.dll; processor="x86"; osname="WindowsXP"
That is copy and pasted from my working manifest. Note the semi-colons! I
had seen some posts were people claimed this should be commas. That seems
to be true when you are separating library versions for different os's,
but when you are including multiple dlls for one os, the dll "folder+name"
stringsneed to be seperated by semi-colons. If you get this wrong, eclipse
findas the last dll in the list but not the previous ones and does not
complain about the syntax.
- I included the dlls in order of their dependence on each other (leaf
first in a dependence tree. I used Dependency Walker
(http://www.dependencywalker.com/) to figure out this order. I don't know
if the order was necessary in the manifest. It is necessary when you start
calling System.LoadLibrary, otherwise Windows does not finde the dependent
libs.
- The PDE FAQ qas helpful in solving these issues.
http://eclipsewiki.editme.com/PDEFaq

- Here is the Syntax for Bundle-NativeCode (showing when to use commas, and
when to use semi-colons!)
http://www.koders.com/java/fid7123785AF3DDA5593BB01D469942C0 B85EF789DA.aspx

Bundle-NativeCode: nativecode-clause ( , nativecode-clause)*
nativecode-clause: nativepaths ( ; env-parameter )*
nativepaths: nativepath ( ;nativepath )*
env-parameter: ( processordef | osnamedef | osversiondef |languagedef )
processordef: <I>processor= </I>token
osnamedef: <I>osname=</I>token
osversiondef: <I>osversion= </I>token
languagedef: <I>language=</I>token

I hope that helps someone. I spent much too long searching about in
newsgroups before this finally worked.....
Previous Topic:removing annoying coolbar actionsets
Next Topic:Executing an RCP application from a single JAR/ZIP file?
Goto Forum:
  


Current Time: Sat Apr 27 02:26:18 GMT 2024

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

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

Back to the top