java中dll文件的加载和卸载。

xiaoxiao2026-08-20  8

一、在java中加载ddl文件的方法:

System.load(dllPath); //dllPath为dll文件的绝对路径。 或者 System.loadLibrary(libname); //libname为dll文件名,该dll要放到类路径中。

 

二、在java中卸载dll文件的方法:

 

private void unloadNativeLibs() { try { ClassLoader classLoader = this.getClass().getClassLoader(); Field field = ClassLoader.class.getDeclaredField("nativeLibraries"); field.setAccessible(true); Vector libs = (Vector) field.get(classLoader); Iterator it = libs.iterator(); Object o; while (it.hasNext()) { o = it.next(); Method finalize = o.getClass().getDeclaredMethod("finalize", new Class[0]); finalize.setAccessible(true); finalize.invoke(o, new Object[0]); } } catch (Exception ex) { log.error("卸载dll文件出错,需要重启服务器!", ex); throw new RuntimeException(ex); } }

 参考:http://www.diybl.com/course/3_program/java/javajs/2007910/71488.html

 

相关资源:使用JNA替代JNI调用DLL,并解决内存溢出问题
转载请注明原文地址: https://www.6miu.com/read-5051564.html

最新回复(0)