Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

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/
like image 775
Nathan Avatar asked Sep 21 '26 04:09

Nathan


1 Answers

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

enter image description here

like image 98
Oo.oO Avatar answered Sep 23 '26 18:09

Oo.oO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!