Share this page 

JNI from a packageTag(s): JNI


JNI requires that the function names follow a specific format. If you have a Java native method in a class called MyClass like this:
public native void myMethod();
the native function must look like this:
JNIEXPORT void JNICALL Java_MyClass_myMethod(JNIEnv *, jobject);
When you put the class into a package (say com.rgagnon), you need to include the package information in the native function name like this:
JNIEXPORT void JNICALL Java_com_rgagnon_MyClass_myMethod(JNIEnv *, jobject);
To generated the proper header, compile the JNI class in the package then, using the javah utility (from the root of the package) :
javah com.rgagnon.MyClass