The test source involved is as follows:
For those who didn ' t install the Java with default settings, a systematic-path for solving JNI class paths problem is:
1> include "System.out.println (System.getproperty (" Java.library.path "));" In your "static" block, right before Loading the class.
2> run your program and isn't surprisingly you got the err again, but this time with Java.library.path info for your Syst Em. (IT ' s important since this path name varies among systems).
3> CP your libxxx.so into the Java.library.path
Java typically uses two Path:classpath and Java.library.path
Classpath is the location that points to the jar package
Java.library.path is the location of a non-Java class package (DLL,SO)
Workaround:
The first method, set the environment variable in the code
The second method: Add-djava.library.path=/usr/local/lib, such as Java-in VM arguments when executing Djava.library.path=. XXX (XXX is the name of a class file, not including the suffix)
The third method: Set the environment variable java.library.path
1: System variable Ld_library_path underLinux to add Java.library.path
2: Which environment variable is set underWindows ???????????????????
If you can't read the above, keep looking down:
1. Put "System.out.println" (System.getproperty ("Java.library.path") before you load the JNI class;
2. Run your program and you will get the directory that Java.library.path points to
3. Copy your libxxx.so to a directory that Java.library.path points to.
Attention:
Linux: Be sure to put Linux under the shared library (I call this:) to name the form of Libxxx.so , "xxx" Is your system.loadlibrary ("xxx") used in the load library name.
Under Windows: Be sure to name the shared library under Windows (I'll call it:) in the form of Xxx.dll ( without the front lib three letters), "xxx" is You in System.loadlibrary (" The name of the load library used in the "XXX").
Looked up other information:
You can also add Java.library.path by setting the system variable Ld_library_path under Linux, as long as you add the following code to the startup ~/.BASHRC and then log back in to the shell, You can put the dynamic library in the current directory to run your JNI program.
Export ld_library_path=.:: $LD _library_path
Alternatively, you can also use the following I ' m new to JNI. I See there is several ways to the set JVM to look for libraries DLLs, so, etc.
System.setproperty ("Java.library.path", ".");
System.loadlibrary ("Hello");
That ' s when unsatisfiedlinkerror
Java.lang.UnsatisfiedLinkError:no Hello in Java.library.path
At Java.lang.ClassLoader.loadLibrary (classloader.java:1682)
At Java.lang.Runtime.loadLibrary0 (runtime.java:822)
At Java.lang.System.loadLibrary (system.java:992)
At Helloworld.main (helloworld.java:17)
Java.lang.UnsatisfiedLinkError:no XXX in Java.library.path