For Programmers: Free Programming Magazines  


Home > Archive > Java Help > July 2004 > JAVA/JNI with packages









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author JAVA/JNI with packages
Remas

2004-07-23, 8:57 am

Hell'ah

How do it?
static native init method that calls RegisterNatives to register the
remaining methods (see below)

Excerpt:
On 19 Jul 2001 08:44:42 -0700, Shon wrote:
> I've written a program Using Java/JNI, and C++. Compiled the java,
> and compiled the dll file. Everything works fine until I place it
> into a package. When I do this I get a
> java.lang.UnsatisfiedLinkError on my method. For the purposes of
> this I dumbed my example down to HelloWorld, which gives me the
> exact same results.


When you move the class into a package, the names of the native
methods must be changed to reflect that.

Simply re-run javah *after* putting the class in a package and use
those names instead of the current ones.

This problem can be (almost) avoided if you have a static native init
method that calls RegisterNatives to register the remaining methods.
Only the init method needs to follow the naming convention and the
others can be named any way you like.

/gordon
Gordon Beaton

2004-07-23, 3:58 pm

On 23 Jul 2004 02:59:57 -0700, Remas wrote:
> How do it?
> static native init method that calls RegisterNatives to register the
> remaining methods (see below)


Start by reading the documentation for RegisterNatives()

In your native library, define an array of JNINativeMethod elements
that describes the mapping from java to native method names. Create a
function JNI_OnLoad() that the JVM will invoke when your library is
loaded. In JNI_OnLoad(), pass the array to RegisterNatives().

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com