wiflish 发表于 2013-2-7 16:31:45

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

一、在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);                finalize.setAccessible(true);                finalize.invoke(o, new Object);            }      } catch (Exception ex) {            log.error("卸载dll文件出错,需要重启服务器!", ex);            throw new RuntimeException(ex);      }    } 参考:http://www.diybl.com/course/3_program/java/javajs/2007910/71488.html
 
页: [1]
查看完整版本: java中dll文件的加载和卸载。