Exception in thread "main" java.lang.ClassNotFoundException: com.baimeidashu.springbootdemo1.Springbootdemo1Application
我用idea 自带的 maven 构建的jiar包没,没问题,
但是用 docker 镜像 maven:3.6.0-jdk-8-alpine 构建的就出问题了报错
pom 文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.baimeidashu</groupId><artifactId>springbootdemo1</artifactId><version>0.0.1-SNAPSHOT</version><name>springbootdemo1</name><description>springbootdemo1</description><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><spring-boot.version>2.6.13</spring-boot.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring-boot.version}</version><configuration><mainClass>com.baimeidashu.springbootdemo1.Springbootdemo1Application</mainClass><layout>ZIP</layout><!--skip为true,意味着执行时跳过这里,设置true 打包时这里没有执行。--><skip>false</skip></configuration><executions><execution><id>repackage</id><goals><!--把依赖的包都打包到生成的Jar包中--><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>
dockerfile 文件如下:
##第1阶段 打包jar
FROM maven:3.6.0-jdk-8-alpine AS buildappWORKDIR /app
COPY pom.xml .
COPY src .RUN mvn clean package -Dmaven.test.skip=trueRUN ls -l && pwd && ls -l target
RUN cp target/*.jar app.jar##第2阶段 构建jra 镜像
#只需要一个jre 运行环境就可以
FROM openjdk:17-jdk
#修改时区,
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
LABEL maintainer="baimeidashu89"
#从第一个阶段的jra 复制过来
COPY --from=buildapp /app/app.jar /app.jarENV JAVA_OPTS="-Xms512m -Xmx2048m -XX:+UseG1GC"
ENV PARAMS="--spring.profiles.active=test"
ENTRYPOINT ["sh","-c","java -Djava.security.egd=file:/dev/./urandom $JAVA_OPTS -jar /app.jar $PARAMS"]
目前错误已经
主要是 自己复制文件有问题, src 目录复制过去,变成了 main