JDK8升级11常见问题

JDK8升级11常见问题

1. 使用rt.jar/jce.jar情况

原代码:

<plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-compiler-pluginartifactId>
        <configuration>
            <source>1.8source>
            <target>1.8target>
            <compilerArguments>
                <bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jarbootclasspath>
            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.projectlombokgroupId>
     <artifactId>lombokartifactId>
     <version>1.18.24version>
 dependency>

3. 程序包 jdk.internal.org.objectweb.asm 不可见

3.1 JDK8中解决方案:在maven-compiler-plugin中添加rt.jar

<plugin>
    <groupId>org.apache.maven.pluginsgroupId>
    <artifactId>maven-compiler-pluginartifactId>
    <configuration>
        <source>1.8source>
        <target>1.8target>
        <compilerArguments>
            <bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jarbootclasspath>
        compilerArguments>
    configuration>
plugin>

3.2 JDK11正确的处理办法

<plugin>
    <groupId>org.apache.maven.pluginsgroupId>
    <artifactId>maven-compiler-pluginartifactId>
    <version>3.8.0version>
    <configuration>
        <source>11source>
        <target>11target>
        <compilerArgs>
            <arg>--add-exportsarg>
            <arg>java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMEDarg>
        compilerArgs>
    configuration>
plugin>

3.3 Idea开发ide的处理方式如下:

Java Compiler添加:

--add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED

JDK8升级11常见问题_第1张图片

你可能感兴趣的:(Java快速开发,java)