JDK8升级11常见问题
1. 使用rt.jar/jce.jar情况
原代码:
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target><compilerArguments><bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath></compilerArguments></configuration></plugin>
修改后:
2. Lombok版本过低
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by lombok.javac.apt.LombokProcessor to field com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs
WARNING: Please consider reporting this to the maintainers of lombok.javac.apt.LombokProcessor
...........
Fatal error compiling: java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTags
修改pom.xml , lombok: 1.16.x - 1.18.x
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.24</version></dependency>
3. 程序包 jdk.internal.org.objectweb.asm 不可见
3.1 JDK8中解决方案:在maven-compiler-plugin中添加rt.jar
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target><compilerArguments><bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath></compilerArguments></configuration>
</plugin>
3.2 JDK11正确的处理办法
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version><configuration><source>11</source><target>11</target><compilerArgs><arg>--add-exports</arg><arg>java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED</arg></compilerArgs></configuration>
</plugin>
3.3 Idea开发ide的处理方式如下:
Java Compiler添加:
--add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED