Some Tips about JNI

  1. The library for JNI invocation is libjvm.so not libjava.so (on Linux) unless you are using a very old version of Java.
  2. For the intercation from Java  to C/C++, no library is needed for compiling and linking since all needed JNI functions are included in jni.h. JNI invocation APIs such as JNI_CreateJavaVM are not included in jni.h. But these APIs are usually not needed in this kind of situation.
  3. For the interaction of C/C++ to Java, only symbols of JNI invcation API are needed to be retrieved with the use of dlsym (on Linux) if dynamic-loading is needed. The reason is the same as Tip 2.
  4. JNI_CreateJavaVM can only be invoked once. This behaviour is not specified in JNI documentation. But it is true for Java 6.

 

你可能感兴趣的:(java,C++,c,linux,jni)