我刚试图使用Java 9运行我的服务器,得到了如下的警告:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/home/azureuser/server-0.28.0-SNAPSHOT.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
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
我希望在启动时不添加--illegal-access=deny
到JVM选项中,就能隐藏此警告。就像这样:
System.setProperty("illegal-access", "deny");
有没有什么方法可以做到这一点?
所有相关的答案都建议使用JVM选项,我想从代码中关闭它。这是否可能?
澄清一下 - 我的问题是关于通过代码关闭此警告,而不是通过类似问题中所述的JVM参数/标志。
HotSpotDiagnosticMXBean
允许更改一些 JVM 选项。不确定是否可以用它来更改这个选项,即使可以,在生产环境中这样做也有些冒险。 - Mick Mnemonic