关于java的System.load 和 System.loadLibrary

关于两者的区别(参见http://blog.csdn.net/ring0hx/article/details/3242245)

System.load 参数为库文件的绝对路径,可以是任意路径。
System.loadLibrary方法load的为相对路径,即在java.library.path定义下的lib文件,文件名会更具不同的系统实现加上不同的前缀、后缀。

例如:System.loadLibrary("foo")

在window中load的是java.library.path路径下的名字为foo.dll的本地类库。

参看http://blog.csdn.net/ring0hx/article/details/3242245

在linux中load的是java.library.path路径下的名字为libfoo.so的本地类库。

参考http://stackoverflow.com/questions/1010503/how-to-debug-a-java-system-loadlibrary-error-in-linux:I think the issue is with the call to System.loadLibrary(String) and using LD_LIBRARY_PATH. Using loadLibrary("foo") will look in your java.library.path for something named libfoo.so. If nothing named libfoo.so is found you will get this error.

在mac中load的是java.library.path路径下的名字为libfoo.jnilib/libfoo.dylib的文件

参见https://www.chilkatsoft.com/java-loadLibrary-MacOSX.asp:From developer.apple.com: "JNI libraries are named with the library name used in the System.loadLibrary() method of your Java code, prefixed by lib and suffixed with .jnilib. For example, System.loadLibrary("hello") loads the library named libhello.jnilib. Java HotSpot also recognizes .dylib as a valid JNI library format as of Mac OS X v10.5."



posted @ 2016-03-21 20:54  xiao晓  阅读(13322)  评论(0编辑  收藏  举报