The amount of the Belch does not start with a BB. Time is pressing.
These two days have been working on the JNI thing, under Windows Normal, but under the Liunx always reported an error, no XXX on Java.library.path, in the Java.library.path can not find the specified so library.
Feel very strange, so use
System.out.println (System.getproperty ("Java.library.path"))
Prints out the path of the Java.library.path. means my path is at sixes and sevens.
Step by step debugging, to the ClassLoader class, found that the file will be confused to find a library of Lib, just started to think that the path did not match well, and later found that the system called a Method: Java.lang.System.mapLibraryName () Culprit. This method will be spliced "Lib" in front of our given name to see its example:
Example the
following Example shows the usage of Java.lang.System.mapLibraryName () method.
Package com.tutorialspoint;
Import java.lang.*;
public class Systemdemo {public
static void Main (string[] args) {
//prints the name of the operating System
System.out.println (System.getproperty ("Os.name"));
/* Maps a library name into a platform-specific string representing
a native library */
string str = System.maplib Raryname ("Os.name");
System.out.println (str);
}
Let-us compile and run the above program, this'll produce the following result−
Linux
libos.name.so
Our loading method is System.loadlibrary ("Aes128converter");
After the end of the program really to find the name into the Java.library.path under the "libaes128converter.so"
The solution is:
When we generate so file in front with a "Lib", so that the program in the runtime to find the so file, in addition, Liunx under the Java Lookup so library path is: ${your JAVA_HOME}/JRE/LIB/AMD64
You need to get two files before you can generate the so library: jni.h, Jni_md.h
They are in the ${your java_home}/include and ${under your java_home}/include/linux, copy them two and need to compile the file in the same folder,
Compile the so file with GCC under Liunx:
Gcc-fpic-shared-o libhelloworld.so HELLOWORLD.C
Specific meaning of each option interested students can go to their own Baidu, here to say, remember in your. c file to refer to your system library or local library, or you will report a compilation error.
More rough, and so have time to tidy up, I hope this article can help friends to step on a little inexplicable pit. Good bye