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>
相關文章
相關標籤/搜索