最近把应用从 JDK 8 升级到 JDK 14, 遇到不少问题 。这些问题是 从 JDK 8 升级到 JDK 11+ (或者 JDK 9+)都容易遇到的问题。 做一个总结分享
1.BASE64Decoder Not found
原先的代码:
import sun.misc.BASE64Decoder;
BASE64Decoder decoder = new BASE64Decoder();
byte[] b = decoder.decodeBuffer(s);
改成 JDK 新版本 java.utilt 里面相应的类:
import java.util.Base64;
Base64.Decoder decoder = Base64.getDecoder();
byte[] b = decoder.decode(s);
2.IDE 里面 Debug 进不了断点
Java 里面这样启动 Spring Boot 应用,开启 Debug 端口:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9009 -jar application/target/ice-editing.jar
然后在 IDEA 里面 Remote Debug, 升级到 JDK 11+ 之后, Remote Debug 不工作,进入不了断点、
IDEA 里面 Debug 的时候, 如果使用 Java 11 以上的 JDK,需要使用 Java 9+ 的这个格式来连接到 JVM:
-agentlib:jdwp=transport=dt_socket,address=*:8787,server=y,suspend=n
3.编译时 出现Lombok 错误
升级 lombok 到新版本
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
- <version>1.14.8</version>
+ <version>1.18.20</version>
<scope>provided</scope>
</dependency>
4.javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath
<!-- FIX Spring Boot on Java 9+, --> <!-- https://stackoverflow.com/questions/51916221/javax-xml-bind-jaxbexception-implementation-of-jaxb-api-has-not-been-found-on-mo --> <!-- for error of : javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath --> <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api --> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.0-b170201.1204</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.activation/activation --> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1</version> </dependency> <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime --> <dependency> <groupId>org.glassfish.jaxb</groupId> <artifactId>jaxb-runtime</artifactId> <version>2.3.0-b170127.1453</version> </dependency> <!-- end of Java 9+ fix -
5.java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
https://github.com/spring-projects/spring-boot/issues/17796
这是 spring boot 的一个 Bug, 可以在启动应用的时候禁用 jar 检查来避免这个问题。
-Dsun.misc.URLClassPath.disableJarChecking=true
.
完整的启动命令:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9009 -Dsun.misc.URLClassPath.disableJarChecking=true -jar application/target/myapp.jar