how does this JNI work anyway??
how does this JNI work anyway??
- Subject: how does this JNI work anyway??
- From: Markian Hlynka <email@hidden>
- Date: Sat, 24 Apr 2004 22:22:38 -0600
Someone just posted a link to Apple's JNI example:
http://developer.apple.com/samplecode/JNISample/JNISample.html
Now, I've looked at this before, and it _works, but I don't understand
_why.
Here is the main java code:
import java.util.*;
public class JNISample {
static {
// Ensure native JNI library is loaded
System.loadLibrary("Example");
}
Ok, so this loads the library "Example".
But from where? I see lots of "Example" files, includein ExampleDylib.c
and .h, and ExampleJNILib.c
But where and what is "Example"??
Here's the constructor:
public JNISample() {
System.out.println("JNISample instance created");
}
And here is the native method:
native int native_method(String arg);
public static void main (String args[]) {
// insert code here...
System.out.println("Started JNISample");
JNISample jniexample = new JNISample();
int result = jniexample.native_method("Hello World !");
System.out.println("Finished JNISample. Answer is " + result);
}
}
Here in the main we just instantiated an object of type JNISample. This
must be a java thing I don't get... How can we be instantiating ourself
from within ourself?? But let's leave that for now. As we see, we
create a JNISample object. Then we call the native_method. But no where
in here have we tied the native method _to anything. The answer must be
in the "Example.*" files.
But the ExampleJNILib.c file contains:
#include "JNISample.h"
What or where is JNISample.h?
#include "ExampleDylib.h"
JNIEXPORT jint JNICALL Java_JNISample_native_1method(JNIEnv *env,
jobject this, jstring arg) {
This line above seems to be the function we're calling, along with a
few other calls in the function. But where is this function tied to the
call to jniexample.native_method? I can understand that whatever this
JNIEXPORT is doing involves pointing at the shared_function in
ExampleDylib.* But what makes it activate when jniexample.native_method
is called?
Can anyone point me at some more [useful] documentation that actually
explains what is going on here?
Thanks,
Markian
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.