Jump to Real's How-to Main page

JNI from a package

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

If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]