Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Writing a plug-in that would have JNI calls
Writing a plug-in that would have JNI calls [message #317186] Wed, 27 June 2007 19:33 Go to next message
Eclipse UserFriend
Hi,

I want to write a plug-in in Eclipse that acts as a front end, which
will have to do JNI call into the service that my plug-in will get data
from. What's the best practice to organize the plug-in, etc.?

Thanks.
Re: Writing a plug-in that would have JNI calls [message #317209 is a reply to message #317186] Thu, 28 June 2007 08:01 Go to previous messageGo to next message
Eclipse UserFriend
A standard plugin will do ... the common pattern is to have your shared
libraries in the root of the plugin, and then include a
Bundle-NativeCode: header in the MANIFEST.MF. There are lots of
examples on the web (google), and the main def looks like:
http://www.docjar.org/docs/api/org/eclipse/osgi/framework/in ternal/core/BundleNativeCode.html

PW
Re: Writing a plug-in that would have JNI calls [message #317213 is a reply to message #317186] Thu, 28 June 2007 09:05 Go to previous messageGo to next message
Eclipse UserFriend
AL wrote:
> Hi,
>
> I want to write a plug-in in Eclipse that acts as a front end, which
> will have to do JNI call into the service that my plug-in will get data
> from. What's the best practice to organize the plug-in, etc.?
>
> Thanks.

Dear AL,

I would like to add some tips and hints...

If your DLL containing the native code need additional DLLs then you
need to provide them with your plug-in *and* you have to load them in
the right order (before your DLL). Load the DLLs only inside a try catch
block that also catches java/lang/Errors because not finding all DLLs
results in a UnresolvedLinkError exception.

The Eclipse plug-in architecture has the side effect of creating a
separate name space for each DLL! Your DLL can only depend on the DLLs
in the same plug-in or DLLs on the global PATH variable.

Windows allows to load a DLL only once per executable, so you cannot
have the same DLL in different plug-ins.

The above two restrictions affect your plug-in partitioning.

In case you need 3rd party DLLs ask the following questions:

* Is multi-threaded access allowed?
* Is the access thread confined (must happen in the same thread)
* Is exit() called inside the DLLs?
* How are error handled? Return code, Popups, exit()?

While testing use the Java options "-verbose:jni" "-Xcheck:jni"!

Be sure to read all the documentation about JNI before starting to
implement anything. Tutorials found on the net are start but not
sufficient for productive use. I'm very satisfied with "The Java Native
Interface Programmers Guide and Specification".

And a final word: Arm yourself with patience. Your are leaving the
convenient world of Java and Eclipse behind!

Bye,

Günther
Re: Writing a plug-in that would have JNI calls [message #318513 is a reply to message #317209] Tue, 31 July 2007 08:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pzabawa.poczta.onet.pl

Hi,
There is an interesting Sun project JNA that simplifies usage of JNI. However I discovered a problem loading library from that project. When I load cpp dll library into Java project everything is OK, however when I load the same library (using the same Java classes) into my PlugIn the loading process hungs. What is the nature of the problem and how it can be solved?
Thank you in advance.
Piotr
Re: Writing a plug-in that would have JNI calls [message #318524 is a reply to message #318513] Tue, 31 July 2007 10:41 Go to previous messageGo to next message
Eclipse UserFriend
Did you use Bundle-NativeCode header in your MANIFEST?

PW
Re: Writing a plug-in that would have JNI calls [message #318583 is a reply to message #318524] Wed, 01 August 2007 02:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pzabawa.poczta.onet.pl

Yes, but when I add the header only (via edition of MANIFEST.MF through Eclipse), the menu I associated library loading (at this stage only) disappears. So, is it enough just to edit MANIFEST.MF this way and insert into it:
"Bundle-NativeCode: CPPDynamicLibToBeCalledViaJNA.dll"?
I tested additional parameters to this line also and the menu disappears each time.
Piotr
Re: Writing a plug-in that would have JNI calls [message #318585 is a reply to message #318583] Wed, 01 August 2007 03:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pzabawa.poczta.onet.pl

Sorry, After Eclipse restart I can see my menu, but the problem with loading dll native library looks still the same.
Re: Writing a plug-in that would have JNI calls [message #318589 is a reply to message #318585] Wed, 01 August 2007 03:22 Go to previous message
Eclipse UserFriend
Originally posted by: pzabawa.poczta.onet.pl

Once again.
I obtain the following exception from Plugin:
"java.lang.NoClassDefFoundError: com/sun/jna/Library"
which is not the case when calling from different Java application project.
I have jna.zip library in "Referenced Libraries" item in Eclipse Package Explorer which is enough in case of different Java application project.
So, what is the reason?
Previous Topic:manipulating source files changes
Next Topic:FormEditor - setPartName
Goto Forum:
  


Current Time: Thu Mar 13 17:17:19 EDT 2025

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

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

Back to the top