Java JDK9:发生了非法的反射访问操作。org.python.core.PySystemState
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46230413/
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
JDK9: An illegal reflective access operation has occurred. org.python.core.PySystemState
提问by IraS
I'm trying to run DMelt programs (http://jwork.org/dmelt/) program using Java9 (JDK9), and it gives me errors such as:
我正在尝试使用 Java9 (JDK9)运行 DMelt 程序 ( http://jwork.org/dmelt/),它给了我以下错误:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Console.encoding()
WARNING: Please consider reporting this to the maintainers of org.python.core.PySystemState
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
How can I fix it? I was trying to add –illegal-access=permit to the last line of the script "dmelt.sh" (I'm using bash in Linux), but this did not solve this problem. I'm very frustrating with this. I was using this program very often, for very long time. Maybe I should never move to JDK9
我该如何解决?我试图将 –illegal-access=permit 添加到脚本“dmelt.sh”的最后一行(我在 Linux 中使用 bash),但这并没有解决这个问题。我对此感到非常沮丧。我经常使用这个程序,很长一段时间。也许我永远不应该迁移到 JDK9
回答by Naman
The idealway to resolve this would be to
解决这个问题的理想方法是
reporting this to the maintainers of org.python.core.PySystemState
将此报告给 org.python.core.PySystemState 的维护者
and asking them to fix such reflective access going forward.
并要求他们在未来修复这种反射访问。
If the default mode permits illegal reflective access, however, then it's essential to make that known so that people aren't surprised when this is no longer the default mode in a future release.
但是,如果默认模式允许非法反射访问,那么必须将其公之于众,以便人们在未来版本中不再是默认模式时不会感到惊讶。
From one of the threads on the mailing list:
从邮件列表上的线程之一:
--illegal-access=permit
This will be the defaultmode for JDK 9. It opens every package in every explicit module to code in all unnamed modules, i.e., code on the class path, just as
--permit-illegal-access
does today.The first illegal reflective-access operation causes a warning to be issued, as with
--permit-illegal-access
, but no warnings are issued after that point. This single warning will describe how to enable further warnings.
这将是JDK 9的默认模式。它打开每个显式模块中的每个包以在所有未命名模块中编码,即类路径上的代码,就像
--permit-illegal-access
今天一样。第一个非法反射访问操作会导致发出警告,与 一样
--permit-illegal-access
,但在那之后不会发出警告。这个单一的警告将描述如何启用进一步的警告。
--illegal-access=deny
This disables all illegal reflective-access operations except for those enabled by other command-line options, such as
--add-opens
. This will become the defaultmode in a future release.
这将禁用所有非法反射访问操作,但由其他命令行选项启用的操作除外,例如
--add-opens
. 这将成为未来版本中的默认模式。
Warning messages in any mode can be avoided, as before, by the judicious use of the --add-exports
and --add-opens
options.
像以前一样,通过明智地使用--add-exports
和--add-opens
选项,可以避免任何模式下的警告消息。
Hence a current temporary solution available is to use --add-exports
as the VM arguments as mentioned in the docs:
因此,当前可用的临时解决方案是--add-exports
用作文档中提到的 VM 参数:
--add-exports module/package=target-module(,target-module)*
Updates module to
export
package totarget-module
, regardless of module declaration. Thetarget-module
can be all unnamedto export to all unnamed modules.
无论模块声明如何,都将模块更新为
export
包target-module
。该target-module
可全部无名出口到所有未命名的模块。
This would allow the target-module
to access all public types in package
. In case you want to access the jdk internal classes which would still be encapsulated, you would have to allow a deep reflectionusing the --add-opens
argument as:
这将允许target-module
访问 中的所有公共类型package
。如果您想访问仍将被封装的 jdk 内部类,则必须允许使用以下参数进行深度反射--add-opens
:
--add-opens module/package=target-module(,target-module)*
Updates module to
open
package totarget-module
, regardless of module declaration.
无论模块声明如何,都将模块更新为
open
包target-module
。
In your case to currently access the java.io.Console
, you can simply add this as a VM option -
在您当前访问 的情况下java.io.Console
,您只需将其添加为 VM 选项 -
--add-opens java.base/java.io=ALL-UNNAMED
Also, note from the same thread as linked above
另外,请注意上面链接的同一线程
When deny
becomes the default mode then I expect permit
to remain supported for at least one release, so that developers can continue to migrate their code. The permit
, warn
, and debug
modes will, over time, be removed, as will the --illegal-access
option itself.
当deny
成为默认模式时,我希望permit
至少在一个版本中得到支持,以便开发人员可以继续迁移他们的代码。的permit
,warn
和debug
模式将随着时间的推移,被去除,如将在本--illegal-access
选项本身。
So it's better to change the implementation and follow the ideal solution to it.
所以最好改变实现并遵循理想的解决方案。
回答by Alan Bateman
DMelt seems to use Jython and this warning is something that the Jython maintainers will need to address. There is an issue tracking it here: http://bugs.jython.org/issue2582
DMelt 似乎使用 Jython,这个警告是 Jython 维护者需要解决的问题。这里有一个问题跟踪它:http: //bugs.jython.org/issue2582
回答by IraS
Jython developers do not have any practical solution for jdk9, according to this post http://bugs.jython.org/issue2582. The previous explanation seems very long to figure out what should done. I just want jdk9 behaves exactly as jdk1.4 - 1.8, i.e be totally silent. The JVM strength in backward comparability. I'm totally OK to have additional options in JDK9, but new features cannot break applications
根据这篇文章http://bugs.jython.org/issue2582,Jython开发人员没有任何适用于 jdk9 的实用解决方案。之前的解释似乎很长,弄清楚应该做什么。我只希望 jdk9 的行为与 jdk1.4 - 1.8 完全一样,即完全保持沉默。JVM 在向后可比性方面的优势。我完全可以在 JDK9 中有其他选项,但新功能不能破坏应用程序
回答by Thilina Sampath
回答by Rob Lassche
Perhaps the fix below works for java 9 as well:
也许下面的修复也适用于 java 9:
In my case the java open jdk version was 10.0.2 and got the same error (An illegal reflective access opeeration has occurred). I upgraded maven to version 3.6.0 on linux, and the problem was gone.
在我的情况下,java open jdk 版本是 10.0.2 并得到相同的错误(发生非法反射访问操作)。我在 linux 上将 maven 升级到 3.6.0 版本,问题消失了。
回答by Drakonoved
To avoid this error, you need to redefine maven-war-plugin
to a newer one. For example:
为避免此错误,您需要重新定义maven-war-plugin
为更新的错误。例如:
<plugins>
. . .
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
P.S.Works for jdk-12
PS适用于jdk-12
回答by QA Specialist
Since the Java update 9, the "illegal reflective access operation has occurred" warning occurs.
自 Java 更新 9 以来,出现“发生非法反射访问操作”警告。
I added --illegal-access=permit
in my eclipse.ini
but it does not resolve the warning when creating a build in eclipse from Maven.
我添加--illegal-access=permit
了我的eclipse.ini
但它没有解决从 Maven 在 Eclipse 中创建构建时的警告。
Try replacing the maven compile plugin. I have resolved this from the Maven Build and Maven Install by modify my pom.xml
file in multiple projects when i did upgrade to from jdk1.8
to jdk1.12
as per the following examples:
尝试更换 Maven 编译插件。我从Maven构建解决了这个和Maven通过修改我的安装pom.xml
在多个项目中的文件时,我从没有升级jdk1.8
到jdk1.12
按照下面的例子:
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 From:
<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 时,“发生非法反射访问操作”消失了。