skip to Main Content

I’m trying to create a docker image for my application. I followed a tutorial and created a DockerFile. Then, it’s displaying this error below.

Error: Could not find or load main class com.yuanhe.demo2.Demo2Application
2023-06-10T00:21:50.430778505Z Caused by: java.lang.ClassNotFoundException: com.yuanhe.demo2.Demo2Application

I wonder what was the correct path. A complete environment setting is shown below.
error message

I tried to replace the last line with

CMD java src.main.java.com.yuanhe.demo2.Demo2Application

and also replace the dots with slashes "/", but none of them works.

2

Answers


  1. I think you are trying to run spring boot application with docker. in the other side you are Dockerizing your spring boot application.
    based on this article, the better way is compiling project and packaging with Maven or Gradle (making JAR file), then make docker image with JAR file, then run container from image.

    Login or Signup to reply.
  2. Check the path to your file again. You have copied the files to the /tmp folder, and you are running from the root.

    Try using this

    ENTRYPOINT ["java", "-cp", "/tmp" "src.main.java.com.yuanhe.demo2.Demo2Application"]
    

    or

    CMD ["java", "-cp", "/tmp" "src.main.java.com.yuanhe.demo2.Demo2Application"]
    

    Both of these commands take an array of arguments, so you need to write [ "1 arg", "2 arg"…]

    I recently made a Dockerfile for my Spring Boot application, you can look at the location of the directories and compare with yours(see from line 55).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search