Mac-Java-(An illegal reflective access operation has occurred)

背景

拉取新项目在本地搭建环境,启动时控制台报错。

  • 本地环境信息
 ~ ❯❯❯ java -version
java version "11.0.5" 2019-10-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)

/ ❯❯❯ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
    11.0.5, x86_64: "Java SE 11.0.5"    /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home

错误信息

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.dom4j.io.SAXContentHandler (file:/Users/baichengyu/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar) to method com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser$LocatorProxy.getEncoding()
WARNING: Please consider reporting this to the maintainers of org.dom4j.io.SAXContentHandler
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

错误原因

JDK版本过高

解决方案

JDK版本降级

  • 官方网站下载安装包安装
    参考地址:https://blog.csdn.net/huawen6/article/details/89182965

  • HomeBrew 安装(安装时间较长)

brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk8
  • 安装完成后查看版本
~ ❯❯❯ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    11.0.5, x86_64: "Java SE 11.0.5"    /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home
    1.8.0_232, x86_64:  "AdoptOpenJDK 8"    /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home
  • IDEA for mac 切换 JDK 版本
    参考地址:https://blog.csdn.net/weixin_41463971/article/details/89318131

你可能感兴趣的:(Mac-Java-(An illegal reflective access operation has occurred))