无法使用 docker:exec 并在同一命令中启动我的 tomcat

问题描述 投票:0回答:1

我一直在尝试启动我的 Tomcat 服务器并在我的 Dockerfile 中作为 CMD 语句运行 mvn exec 命令,但我遇到了以下错误,并且无法弄清楚:

Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher

这是我的 dockerfile:

FROM maven:3.8.5-openjdk-11-slim AS builder

WORKDIR /app

COPY . .

RUN mvn clean package


RUN mvn --version # Runs fine


FROM tomcat:10-jdk11

WORKDIR /app

COPY --from=builder /app/target/project.war /usr/local/tomcat/webapps/project.war

EXPOSE 8080

CMD mvn exec:java -Dexec.cleanupDaemonThreads=false -Dexec.mainClass="MyClass" && catalina.sh run

我已经尝试了很多方法,但仍然无法弄清楚。

java docker maven servlets war
1个回答
0
投票

您必须创建一个名为

start.sh
的文件,如下所示:

/bin/bash

mvn exec:java -Dexec.cleanupDaemonThreads=false -Dexec.mainClass="MyClass" && catalina.sh run

然后,更改 Dockerfile,如下所示:

FROM maven:3.8.5-openjdk-11-slim AS builder

WORKDIR /app

COPY . .

RUN mvn clean package


RUN mvn --version # Runs fine


FROM tomcat:10-jdk11

WORKDIR /app

COPY --from=builder /app/target/project.war /usr/local/tomcat/webapps/project.war

COPY start.sh .

EXPOSE 8080

CMD start.sh
© www.soinside.com 2019 - 2024. All rights reserved.