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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM