美文网首页
记录一下System.loadLibrary和System.lo

记录一下System.loadLibrary和System.lo

作者: 人人为它 | 来源:发表于2022-05-24 10:14 被阅读0次

主要是工作和硬件打交道过.而且公司用的JNI.然后dll就在工程根目录很多

想封装一下.那某些库要用的jni封装到那个库里面.

遂试了一下.

static

{

System.loadLibrary("a")

}

如果把a和a的依赖bcdef全部放在工程根目录.能够正常加载

但是如果在工程根目录新建一个叫dll的dir

然后通过-Djava.library.path=SRC_ROOT/dll

这样.就会报hs_err.虚拟机直接崩溃了.

说明应该是依赖没找到

但是我把dll的名字改成dll2

去启动就报no ain java.library.path

那说明其实参数设置是有效的啊

我就奇怪了.这个a的依赖他到底是不是有java层面的libraryPath去找的.

因为dll的加载都是在classLoad

NativeLibrary lib =newNativeLibrary(fromClass,name,isBuiltin);

nativeLibraryContext.push(lib);

try{

lib.load(name,isBuiltin);

}finally{

nativeLibraryContext.pop();

}

if(lib.loaded) {

loadedLibraryNames.addElement(name);

libs.addElement(lib);

return true;

}

static classNativeLibrary {

// opaque handle to native library, used in native code.

longhandle;

// the version of JNI environment the native library requires.

private intjniVersion;

// the class from which the library is loaded, also indicates

// the loader this native library belongs.

private finalClassfromClass;

// the canonicalized name of the native library.

// or static library name

Stringname;

// Indicates if the native library is linked into the VM

booleanisBuiltin;

// Indicates if the native library is loaded

booleanloaded;

native voidload(String name, booleanisBuiltin);

是个native方法.我就怀疑是不是jvm这B.根本没有管这个参数?

但是网上大佬都说可以啊..

我迷了.

相关文章

网友评论

      本文标题:记录一下System.loadLibrary和System.lo

      本文链接:https://www.haomeiwen.com/subject/vmljprtx.html