BlueXIII's Blog

热爱技术,持续学习

0%

老项目添加JDK17支持

Pom依赖添加

需要添加缺失的依赖以避免找不到类的问题

在根pom.xml中,添加Java17缺失依赖

1
2
3
4
5
6
7
8
9
10
11
<!--Java17缺失依赖-->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>

Dockerfile修改

需要修改java启动参数以允许深度反射

  1. 基础镜像改为openjdk:17-oracle
  2. 启动命令中加入--add-opens参数

原始:

1
2
3
4
5
6
7
8
9
FROM java:8
MAINTAINER la
ENV TZ=Asia/Shanghai
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /dubhe-quality-biz
WORKDIR /dubhe-quality-biz
EXPOSE 8604
ADD ./dubhe-quality/dubhe-quality-biz/target/dubhe-quality-biz.jar ./
CMD java -Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom -jar dubhe-quality-biz.jar

修改后:

1
2
3
4
5
6
7
8
9
FROM openjdk:17-oracle
MAINTAINER la
ENV TZ=Asia/Shanghai
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /dubhe-quality-biz
WORKDIR /dubhe-quality-biz
EXPOSE 8604
ADD ./dubhe-quality/dubhe-quality-biz/target/dubhe-quality-biz.jar ./
CMD java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED -Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom -jar dubhe-quality-biz.jar

Alias修改

1
2
vi .zshrc
alias java="java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED"