【发布时间】:2021-11-12 01:58:27
【问题描述】:
我下面的spring boot应用有问题,我需要包含一个spring boot应用才能在mac上本地运行它,为此我编写了如下所示的dockerfile,容器图像生成正确但是当我把它在运行中我有以下错误,这是什么原因造成的,这可能是什么? 要做到这一切,我使用下面的 shell 文件,我该如何修复错误?
错误:
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/reportserver/report/ReportApplication has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
docker.sh:
#!/bin/bash
#define docker name
dockername=quote
#Delete all containers and all volumes
docker system prune -a
#Build of container and image
docker build -t $dockername .
#Run container
docker run --publish 8081:8081 $dockername
Dockerfile:
FROM openjdk:alpine
EXPOSE 8081
ARG JAR_FILE=target/report-0.0.1-SNAPSHOT.jar
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
【问题讨论】:
-
看来编译用的JDK版本和容器的jdk有区别。尝试在Dockerfile中指定相同版本的openjdk,如
openjdk:18-jdk-alpine3.13
标签: spring spring-boot docker shell