最近要在servlet 中使用opencv,发现在java文件中,使用main可以跑通的代码,在servlet中不能跑通了。
//动态加载dll
private void loaddllDynamically() {
String yourdllpath=“”//输入你要的dll路径,例如“c:/opencv/”,路径下为opencv_320,dll位置
try {
//设置路径
System.setProperty("java.library.path",yourdllpath + System.getProperty("java.library.path"));
System.out.printf("java.library.path: %s%n",System.getProperty("java.library.path"));
Field fieldSysPath;
fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
} catch (NoSuchFieldException |SecurityException | IllegalArgumentException | IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}