UnsatisfiedLink错误:opencv_java2411.dll已在玻璃鱼中的另一个类加载器中加载 [英] UnsatisfiedLink error : opencv_java2411.dll already loaded in another classloader in glass fish

查看:272
本文介绍了UnsatisfiedLink错误:opencv_java2411.dll已在玻璃鱼中的另一个类加载器中加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opencv在Java中实现用于人脸识别的Web应用程序. 在运行用于人脸识别的代码时,出现了

I am implementing a web application for face recognition in java using opencv. While I am running the code for face recognition I am getting errors like

java.lang.UnsatisfiedLinkError: Native Library F:\opencv\build\java\x86\opencv_java2411.dll already loaded in another classloader

我已经完成了几种在Internet上可用的方法,例如检查类是否已加载,是否将system.loadlibrary作为静态块添加到环境变量的路径等等,但是在所有这些过程之后,错误仍然存​​在于系统中. /p>

i had done several methods avaliable over internet such as checking whether the class is loaded or not making the system.loadlibrary as static block adding path to environment variable and so on but the error persist in the system after all this process.

does anyone has the solution for this problem i am able to run with this dll in desktop application but while running in web application the error comes 

i am running this project using glassfish server on netbeans ide 



public class FaceRecognition {
   public static boolean loaded = false;


 public void loadLib(){
     System.out.println("loading library");
     try {
       System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 
     }catch(Exception e){}
        loaded = true;
 }

    public FaceRecognition() {

    }



    public void  saveFaceRecognizedImage(File file){


        try {
            MatOfByte mem = new MatOfByte();

            CascadeClassifier faceDetector = new CascadeClassifier(facerecog.FaceRecognition.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
            MatOfRect faceDetections = new MatOfRect();

            BufferedImage bi = ImageIO.read(file);
            Mat frame = bufferedImageToMat(bi);


            Rect rectcrop = null;
            faceDetector.detectMultiScale(frame, faceDetections);
            for (Rect rect : faceDetections.toArray()) {
                System.out.println("ttt");
                Core.rectangle(frame, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                        new Scalar(0, 255,0));
                 rectcrop = new Rect(rect.x,rect.y,120,120);
            }
             try {
                                Mat imgrr = new Mat(frame,rectcrop);
                                Highgui.imwrite(file.getAbsolutePath(), imgrr);
//                                BufferedImage image = ImageIO.read(file);
//                                 BufferedImage scaled = getScaledInstance(
//            image, 120,120, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
//        writeJPG(scaled, new FileOutputStream(file.getAbsolutePath()), 0.85f);
                            }catch(Exception e){}


//            Highgui.imencode(".bmp", frame, mem);
//            Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
//            BufferedImage buff = (BufferedImage) im;
//            ImageIO.write(buff,"jpg",file);
        } catch (IOException ex) {
            Logger.getLogger(FaceRecognition.class.getName()).log(Level.SEVERE, null, ex);
        }

}

推荐答案

每个

每个类加载器管理自己的一组本机库. 相同 JNI本机库不能加载到多个类加载器中. 这样做会引发UnsatisfiedLinkError.例如, 当System.loadLibrary用来加载文件时抛出UnsatisfiedLinkError 本机库分为两个类加载器.

Each class loader manages its own set of native libraries. The same JNI native library cannot be loaded into more than one class loader. Doing so causes UnsatisfiedLinkError to be thrown. For example, System.loadLibrary throws an UnsatisfiedLinkError when used to load a native library into two class loaders.

在应用程序服务器中,应用程序的每个实例都使用一个新的类加载器,因此,如果多个应用程序尝试加载同一个本机库,或者在不重新启动整个应用程序服务器的情况下重新启动了单个应用程序,您将看到此错误.一些选项:

In an application server, each instance of an application uses a new class loader, so you will see this error if multiple applications try to load the same native library or if a single application is restarted without restarting the entire application server. Some options:

  1. 从服务器级的类加载器加载本机库,该类库可由服务器中的所有应用程序共享,并且在重新启动应用程序时不会重新创建.大多数应用程序服务器都支持此功能,但是配置是特定于产品的.
  2. 如果仅单个应用程序正在访问本机库,但正在重新启动,则请重新启动整个应用程序服务器JVM.
  3. 如果多个应用程序正在访问本机库,则将本机库复制到其他位置以诱使JVM将其加载两次.

这篇关于UnsatisfiedLink错误:opencv_java2411.dll已在玻璃鱼中的另一个类加载器中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆