简单的Java应用程序在Docker中 – 无法找到或加载主类

huangapple go评论74阅读模式
英文:

Simple Java Application in Docker - Could not find or load Main class

问题

我已经创建了一个简单的 Eclipse 项目,在 src/com/docker/Main.java 内有 Main 类。
当我尝试在构建图像后在 Docker 容器内运行它时,会出现 "Could not find or load main class" 错误。

Docker 图像内容:

FROM openjdk:8
COPY . /app/
WORKDIR /app
RUN javac src/com/docker/Main.java

CMD ["java", "com.docker.Main"]

我尝试了几种 RUN 和 CMD 的变化,但都没有成功。我尝试过使用斜杠 '/',但仍然没有成功。

CMD ["java", "com.docker.Main.java"]
CMD ["java", "com.docker.Main.class"]

如果我在 javac 部分之后运行以下命令,它会列出 Main.javaMain.class 文件。

RUN ls src/com/docker/
英文:

I have created a simple Eclipse project having Main class inside src/com/docker/Main.java.
When i try to run it inside a docker container after building the image, i get the Could not find or load main class error.

Docker image content:

FROM openjdk:8
COPY . /app/
WORKDIR /app
RUN javac src/com/docker/Main.java

CMD ["java", "com.docker.Main"]

I tried several variations of RUN and CMD but nothing worked. I tried with slashes '/' but still did not worked.

CMD ["java", "com.docker.Main.java"]
CMD ["java", "com.docker.Main.class"]

If i run the following command after the javac part, it lists Main.java and Main.class files.

RUN ls src/com/docker/

答案1

得分: 2

好的,以下是您要的翻译内容:

也许这张图片会更好地解释这些参数。

简单的Java应用程序在Docker中 – 无法找到或加载主类

英文:

Well, maybe this picture will explain the parameters little bit more.

简单的Java应用程序在Docker中 – 无法找到或加载主类

huangapple
  • 本文由 发表于 2020年9月16日 15:12:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63914913.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定