問題描述
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>