1.它们都可以用来装载库文件,不论是JNI库文件还是非JNI库文件。在任何本地方法被调用之前必须先用这个两个方法之一把相应的JNI库文件装载。
2.System.load 参数为库文件的绝对路径,可以是任意路径。
例如你可以这样载入一个windows平台下JNI库文件:
System.load("C:\\Documents and Settings\\TestJNI.dll");。
3. System.loadLibrary 参数为库文件名,不包含库文件的扩展名。
例如你可以这样载入一个windows平台下JNI库文件
System. loadLibrary ("TestJNI");
这里,TestJNI.dll 必须是在java.library.path这一jvm变量所指向的路径中。
可以通过如下方法来获得该变量的值:
System.getProperty("java.library.path");
默认情况下,在Windows平台下,该值包含如下位置:
1)和jre相关的一些目录
2)程序当前目录
3)Windows目录
4)系统目录(system32)
5)系统环境变量path指定目录
4.如果你要载入的库文件静态链接到其它动态链接库,例如TestJNI.dll 静态链接到dependency.dll, 那么你必须注意:
1)如果你选择
System.load("C:\\Documents and Settings\\ TestJNI.dll");
那么即使你把dependency.dll同样放在C:\\Documents and Settings\\下,load还是会因为找不到依赖的dll而失败。因为jvm在载入TestJNI.dll会先去载入TestJNI.dll所依赖的库文件dependency.dll,而dependency.dll并不位于java.library.path所指定的目录下,所以jvm找不到 dependency.dll。
你有两个方法解决这个问题:一是把C:\\Documents and Settings\\加入到java.library.path的路径中,例如加入到系统的path中。二是先调用
System.load("C:\\Documents and Settings\\ dependency.dll"); 让jvm先载入dependency.dll,然后再调用System.load("C:\\Documents and Settings\\ TestJNI.dll");
2)如果你选择
System. loadLibrary ("TestJNI");
那么你只要把dependency.dll放在任何java.library.path包含的路径中即可,当然也包括和TestJNI.dll相同的目录。
附load方法:
/* * Loads and links a library without security checks. */ void load(String filename, ClassLoader loader) { if (filename == null) { throw new NullPointerException("library path was null."); } String error = nativeLoad(filename, loader); if (error != null) { throw new UnsatisfiedLinkError(error); } }
loadLibrary方法:
/* * Loads and links a library without security checks. */ void loadLibrary(String libraryName, ClassLoader loader) { if (loader != null) { String filename = loader.findLibrary(libraryName); if (filename == null) { throw new UnsatisfiedLinkError("Couldn't load " + libraryName + ": " + "findLibrary returned null"); } String error = nativeLoad(filename, loader); if (error != null) { throw new UnsatisfiedLinkError(error); } return; } String filename = System.mapLibraryName(libraryName); List<String> candidates = new ArrayList<String>(); String lastError = null; for (String directory : mLibPaths) { String candidate = directory + filename; candidates.add(candidate); if (new File(candidate).exists()) { String error = nativeLoad(candidate, loader); if (error == null) { return; // We successfully loaded the library. Job done. } lastError = error; } } if (lastError != null) { throw new UnsatisfiedLinkError(lastError); } throw new UnsatisfiedLinkError("Library " + libraryName + " not found; tried " + candidates); }
相关推荐
以下是对System.load与System.loadLibrary进行了详细的分析介绍。需要的朋友可以过来参考下
LoadLIbrary示例
java调用Gmssl中国密接口进行对称与非对称加解密等运算,动态so库进行接口jni方式调用,采取接口形式对外暴露,方便对接系统调用相关java接口进行相关运算操作。
loadLibrary msc error:java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.example.xflinean-1/base.apk”],nativeLibraryDirectories=[/vendor/lib, /system/...
示范如何使用 LoadLibrary(...) 和 GetProcAddress(....)调用dll的输出函数.
对象的使用包括引用对象的成员变量和方法,通过运算符·可以实现对变量的访问和方法的调 用,变量和方法可以通过设定一定的访问权限(见下面的例子)来允许或禁止其它对象对它的 访问。 我们先定义一个类 Point。 例子...
Android安卓源码解析,比较详细的分析了Sytem.loadLibrary的源码,对于so文件的dump的点有非常好的借鉴意义
loadlibrary failed with error 126:找不到指定模块
java调用动态库(Jnative).zip
在这个例子中,我们使用Java Native Interface(JNI)来调用本地的C++代码。首先,我们需要在Java类中声明一个native方法,并使用`native`...这些参数可以让我们方便地在Java和C++之间传递数据和调用其他本地方法。
创建javaApp工程 d.将JNative.jar添加到工程中 e.参考如下代码,编写后编译执行,并运行 import org.xvolks.jnative.JNative; import org.xvolks.jnative.Type; import org.xvolks.jnative.exceptions.Native...
用java实现在命令方式清屏 java实现清屏功能 1. 编写一个类ClearScreen.java public class ClearScreen{ Static { loadLibrary("Clear"); } public native static void clearScreen(); public static void ...
t532.rar 测试代码 https://blog.csdn.net/wowocpp/article/details/105382257 python 调用 C++ dll 32位 64位 问题 ctypes.cdll.LoadLibrary
解决win10操作系统,初始化Eo Webbrowser报错"Failed to resolve LoadLibrary",需要调用eowp.exe,来进行处理,Both EO.Pdf and EO.WebBrowser dynamically create child processes and run browser engine inside ...
java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared from loader dalvik.system.PathClassLoader: findLibrary returned null at java.lang.Runtime.loadLibrary(Runtime.java:365) at java.lang.System...
本文将介绍三种方法: 1、Windows 钩子 2、CreateRemoteThread 和 LoadLibrary 技术 ——进程间通信 3、CreateRemoteThread 和WriteProcessMemory 技术 ——如何用该技术子类化远程控件 ——何时使用该技术
CAD2014启动出现loadlibrary failed with error 87-附件资源
jacob.jar1.19及使用方法 解压后获得3个文件 jacob.jar jacob-1.17-x64.dll jacob-1.17-x86.dll jacob.jar 放到项目的lib目录 win7 jacob-1.17-x64.dll 放到C:\Windows\System32 jacob-1.17-x86.dll 放到C:\...
Java + Opencv进行图像匹配、图像识别、计算机视觉处理时需要调用opencv本机库,光通过pom添加opencv的jar依赖不行。 因为OpenCV的核心功能是由本机库文件提供的,这些本机库文件是用C++编写的,并且与具体的操作...
近一个项目要开发网页端人脸识别项目,人脸识别的算法已经写好,是C++版,但是网页端要求使用Java后台,这涉及到Java调用DLL的问题。经过查找,实现了一个简单的例子。 1、第一步,先在Java中新建一个类 ...