-
更改环境变量JAVA_HOME路径配置为JDK13路径
配置maven settings.xml 在profiles节点下增加
<profile>
<id>jdk13</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>13</jdk>
</activation>
<properties>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
<maven.compiler.compilerVersion>13</maven.compiler.compilerVersion>
</properties>
</profile>
- 修改项目pom.xml文件properties节点
<java.version>13</java.version>
- 代码修改
1、编译报错
1、sun.misc.BASE64Encoder、sun.misc.BASE64Decoder找不到类
(1)原因:JDK11中删除了sum.misc包
(2)解决方式:使用java.util.Base64.Encoder、java.util.Base64.Decoder替换
2、服务启动报错
(1)WARNING: Unable to start embedded Tomcat(启动eureka服务时)
原因:JDK11下使用最新的Greenwich版本的eureka默认情况下必定无法启动,日志提示内嵌的Tomcat没法启动。官方原文:
The JAXB modules which the Eureka server depends upon were removed in JDK 11. If you intend to use JDK 11 when running a Eureka server you must include these dependencies in your POM or Gradle file.
解决办法:加入JAXB依赖
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
(2)WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/E:/WorkSpace/IDEs/MAVEN/RepositoryMicro/com/thoughtworks/xstream/xstream/1.4.10/xstream-1.4.10.jar) to field java.util.TreeMap.comparator(启动客户端服务时)
原因:JDK9以后的版本,模块化的概念去除了JAXB(默认没有加载),需做接入声明。
解决办法:加入JAXB依赖
<!-- jdk11 jaxb模块引用 start -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- jdk11 jaxb模块引用 end -->