java9模块不可见问题

问题描述

jdk.internal.reflect包不可见

问题原因

java9模块化之后,java.base只把jdk.internal.reflect暴露给了少数几个内部包而没有向当前模块暴露。

解决方法

alt+enter IDEA会自动提示解决方案,它的解决方案只针对.idea/compiler.xml。即便直接运行程序不报错,在执行mvn compile时也会报错,说jdk.internal.reflect不可见。

<component name="JavacSettings">
  <option name="ADDITIONAL_OPTIONS_OVERRIDE">
    <module name="hanlp" options="--add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED,hanlp" />
  </option>
</component>

需要进一步更改compiler插件的命令行参数

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>12</source>
        <target>12</target>
        <encoding>utf-8</encoding>
        <showDeprecation>true</showDeprecation>
        <showWarnings>true</showWarnings>
        <compilerArgument>
            --add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED,hanlp
        </compilerArgument>
    </configuration>
</plugin>

猜你喜欢

转载自www.cnblogs.com/weiyinfu/p/11108091.html
今日推荐