【发布时间】:2018-08-24 04:41:42
【问题描述】:
我想制作一个可移植的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());
}
}
我将此添加到pom.xml:
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-0</version>
<scope>compile</scope>
</dependency>
它适用于以下警告对于 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]
更新:以及针对 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'.
折叠 maven 依赖文件夹中的 opencv jar 显示所有库都是灰色的,如下所示:
如果我忽略此警告并且不将库与警告消息中提到的命令链接怎么办? 因为用java做opencv移植很简单,我想实现如果没有问题,以后继续这个方法。
我使用 JDK 9、Eclipse Oxygen.2、Fedora 27。
将来,应用程序的目标可能是 windows。
【问题讨论】:
-
看起来它正在侵入 java.lang.ClassLoader 中的私有字段。可能是该库的作者不知道 System.load(您在其中指定库的文件路径而不是其名称)。
-
@AlanBateman 有什么办法可以解决吗?我在GitHub上评论,请作者看问题。
-
抱歉,我不知道 opencv,但向维护者问题跟踪器提交问题似乎是解决此问题的正确方法。
标签: java maven opencv java-9 javacv