警告:发生了非法的反射访问操作(java 中的便携式 opencv)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49298293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WARNING: An illegal reflective access operation has occurred (portable opencv in java)
提问by Merlin
I want to make a portable opencv
application which the dependency is added to maven file pom.xml
.
我想制作一个可移植的opencv
应用程序,将依赖项添加到 maven 文件中pom.xml
。
Simplified code is :
简化代码是:
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());
}
}
I added this to pom.xml
:
我将此添加到pom.xml
:
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-0</version>
<scope>compile</scope>
</dependency>
It works with the following warning for java 9:
它适用于 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]
UPDATE:And the following warning for java 8:
更新:以及 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'.
Collapsing the opencv jar in maven dependency folder shows that all the libraries are in grayed color as depicted here:
折叠 maven 依赖文件夹中的 opencv jar 显示所有库都呈灰色,如下所示:
What if I ignore this warning and don't link the libraries with the mentioned command in the warning message? Because it was very simple to make the opencv portable with java and I want to realize if there is no problem then continue this method in future.
如果我忽略此警告并且不将库与警告消息中提到的命令链接怎么办?因为用java使opencv可移植非常简单,我想意识到如果没有问题,那么以后继续这种方法。
I use JDK 9, Eclipse Oxygen.2, Fedora 27.
我使用 JDK 9、Eclipse Oxygen.2、Fedora 27。
In future, the application's target might be windows.
将来,应用程序的目标可能是 windows。
回答by Saad
This occurred because of Java 9 new checks of illegal access, and it is common to have such kind of security warnings after the release of java 9. The permanent solution to this is to report the bug to the maintainers and wait for them to release a patch update.
这是因为 Java 9 对非法访问进行了新的检查,并且在 Java 9 发布后经常出现此类安全警告。对此的永久解决方案是将错误报告给维护者并等待他们发布一个补丁更新。
However only at your own risk, yes you can continue withoutsecurity features i.e stack guard, depending on your use and scope of this package under discussion.
但是,只有您自己承担风险,是的,您可以在没有安全功能(即堆栈保护)的情况下继续,具体取决于您所讨论的此软件包的使用和范围。
回答by QA Specialist
Since the Java update 9, the "illegal reflective access operation has occurred" warning occurs.
自 Java 更新 9 以来,出现“发生非法反射访问操作”警告。
Try replacing the maven compiler plugin. I have resolved this from Maven Build and Maven Install by modifying my pom.xml file in multiple projects when I did upgrade to from jdk1.8 to jdk1.12 as per the following examples:
尝试更换 maven 编译器插件。当我按照以下示例从 jdk1.8 升级到 jdk1.12 时,我通过修改多个项目中的 pom.xml 文件,从 Maven Build 和 Maven Install 解决了这个问题:
Change version from:
更改版本:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<webXml>WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
To:
到:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<webXml>WebContent\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
And also changed the artifactId and version from:
并且还从以下位置更改了 artifactId 和 version:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
To:
到:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
When I re-run Maven Build or Maven Install, the "illegal reflective access operation has occurred" is gone.
当我重新运行 Maven Build 或 Maven Install 时,“发生非法反射访问操作”消失了。