Building a jar file and from the jar file an image of a spring boot application using maven in docker using dockerfile

  docker, java, maven, spring, spring-boot

I have a spring application. I want to utilize multi stage builds and first build a jar file, and then use this jar file when building a docker image. I don’t have a jar image built before the dockerfile is ran.

FROM openjdk:8-jdk as BUILD
COPY src/main/java/myapp/ /src/
RUN cd /src/ 
 && javac (or use mvnmw....?)

FROM openjdk:8-jre as run
COPY --from=build /src/ /src/myapp/
CMD ["java"]

So I first wish to build java file into a jar file and later use that jar file to produce an image. All examples already assume there is a jar file already.

Source: Docker Questions