警告:发生了非法反射访问操作(java 中的便携式 opencv)

Mar*_*tin 6 java opencv maven javacv java-9

我想制作一个便携式opencv应用程序,将依赖项添加到 maven 文件中pom.xml

简化的代码是:

import org.opencv.core.Mat;

public class Builder {

    public static void main(String[] args) {

        nu.pattern.OpenCV.loadShared();
        System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);

        Mat mat = new Mat(4,3,1);
        System.out.println(mat.dump());
    }
}
Run Code Online (Sandbox Code Playgroud)

我将此添加到pom.xml

<dependency>
      <groupId>org.openpnp</groupId>
      <artifactId>opencv</artifactId>
      <version>3.2.0-0</version>
      <scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

它适用于 java 9 的以下警告:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by nu.pattern.OpenCV$SharedLoader (file:/home/martin/.m2/repository/org/openpnp/opencv/3.2.0-0/opencv-3.2.0-0.jar) to field java.lang.ClassLoader.usr_paths
WARNING: Please consider reporting this to the maintainers of nu.pattern.OpenCV$SharedLoader
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library /tmp/opencv_openpnp6598848942071423284/nu/pattern/opencv/linux/x86_64/libopencv_java320.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
101, 115,  47;
 108, 105,  98;
  47, 108, 105;
  98, 111, 112]
Run Code Online (Sandbox Code Playgroud)

更新:以及 java 8 的以下警告:

Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library/tmp/opencv_openpnp3835511967220002519/nu/pattern/opencv/linux/x86_64/libopencv_java320.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Run Code Online (Sandbox Code Playgroud)

折叠 maven 依赖文件夹中的 opencv jar 显示所有库都呈灰色,如下所示:

opencv 3.2的maven依赖文件夹

如果我忽略此警告并且不将库与警告消息中提到的命令链接怎么办?因为用java让opencv移植非常简单,我想意识到如果没有问题,那么将来继续这个方法。

我使用 JDK 9、Eclipse Oxygen.2、Fedora 27。

将来,应用程序的目标可能是Windows。

小智 5

出现这种情况是因为Java 9新增了对非法访问的检查,并且在Java 9发布后出现此类安全警告是很常见的。永久的解决方案是向维护者报告该错误并等待他们发​​布错误补丁更新。

但是,只有您自己承担风险,是的,您可以在没有安全功能(即堆栈防护)的情况下继续,具体取决于您所讨论的此包的使用和范围。