'Docker could not find or load main class. Caused by: java.lang.ClassNotFoundException: src.com.company.Main.java
I am new to learning Docker, and followed a tutorial to make a small Hello World application to dockerize. I used Intellij template to generate a main method, which lies in the "com.company" package. All the method does is print out "Hello World!".
The problem is when I try to run the image from the terminal, it gives me this error:
Error: Could not find or load main class src.com.company.Main.java
Caused by: java.lang.ClassNotFoundException: src.com.company.Main.java
I made a Docker file that looks like this:
FROM openjdk:11
RUN mkdir /app
COPY out/production/DockerTestApp/com/company/Main.class/ /app
WORKDIR /app
CMD java src/com/company/Main.java
For the "COPY" path, I just copied the Content Root path of the Main class in the "out" folder.
For the CMD path, I copied the Content Root path in the "src" folder.
This is the command I use to build the image(I give it a new TAG everytime):
docker build -t hello-world:3.0 .
I have tried writing the paths differently and creating the image again, but I just dont understand how Im supposed to write it.
I appreciate your help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
