在 Java 11 下运行 Eclipse 时,使用google-java-format eclipse 插件效果很好,但在 Java 16+ 上运行时,它会失败并出现以下错误:
完整错误:A save participant caused problems. The save participant 'Code Clean Up' caused an exception: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x99c5646) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x99c5646. See the error log for details.
google-java-formatter确实注意到--add-exports
,在 JDK 16+ 上运行时,由于 JEP-396(JDK 内部的强封装),您需要在运行格式化程序时设置标志。不清楚的是如何--add-exports
为 Eclipse 插件设置设置。
添加以下内容eclipse.ini
(或在我的情况下SpringToolSuite4.ini
)似乎没有帮助(更不用说感觉不对,因为它没有针对那个特定的插件)。有没有不同的方法来解决/解决这个问题?
-vmargs
-Dosgi.requiredJavaVersion=11
-Dosgi.dataAreaRequiresExplicitInit=true
-Xms256m
-Xmx2048m
--illegal-access=permit
--add-modules=ALL-SYSTEM
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED