发布于 
pv: - | uv: -

Java提示非法映射的解决方法

这些天,因为某些原因重装了树莓派的系统,安装往常的操作方法安装了open-jdk,但是在运行server.jar时却提示:
root@xcsoftpi:/home/pi# java -Xmx2000M -Xms2000M -jar server.jar
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.PlatformDependent0 (file:/home/pi/server.jar) to field java.nio.DirectByteBuffer.cleaner
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.PlatformDependent0
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
X月 XX, 2020 XX:XX:XX 上午 io.netty.util.internal.PlatformDependent
信息: Your platform does not provide complete low-level API for accessing direct buffers reliably. Unless explicitly requested, heap buffer will always be preferred to avoid potential system unstability.

对于这种情况我们可以尝试回退java的版本(使用旧版java)

首先我们先输入java -version查询下目前java的版本

root@xcsoftpi:/home/pi# java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Raspbian-1deb10u1)
OpenJDK Server VM (build 11.0.6+10-post-Raspbian-1deb10u1, mixed mode)

的确太新了(╯°A°)╯︵○○○对旧版java程序不友好啊,还是用了很长时间的java1.8比较友好啊.

接下来输入update-alternatives --config java切换成1.8的版本.

root@xcsoftpi:/home/pi# update-alternatives --config java
有 2 个候选项可用于替换 java (提供 /usr/bin/java)。

  选择       路径                                          优先级  状态
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-armhf/bin/java      1111      自动模式
  1            /usr/lib/jvm/java-11-openjdk-armhf/bin/java      1111      手动模式
  2            /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java   1081      手动模式

要维持当前值[*]请按<回车键>,或者键入选择的编号:2
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java 来在手动模式中提供 /usr/bin/java (java)

这时再查询下当前java版本-java -version

root@xcsoftpi:/home/pi# java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1+rpi1-b01)
OpenJDK Client VM (build 25.212-b01, mixed mode)

此时你的java程序已经可以正常使用了!