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[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

 

你可能感兴趣的:(java,html)