英文:
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.java
和 Main.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
好的,以下是您要的翻译内容:
也许这张图片会更好地解释这些参数。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论