java9模块不可见问题

问题描述

jdk.internal.reflect包不可见java

问题缘由

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

解决方法

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

<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插件的命令行参数ide

<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>
相关文章
相关标签/搜索