2

I need to understand how to deal with common libraries that i have created which my Application depends upon. When i create jar for this app using maven it creates a package. But how do we maintain or configure other common libraries which are listed in pom.xml of this application?

should we have maven also as an image in the docker file?

Please explain in detail.

My current progress is explained below: I have an Application A which has other dependencies like B and C libraries which i have specified in pom.xml. When i run application A in my local system it uses local repository that i have configured in user settings for maven. SO it works fine.

So how do we maintain this in kubenetes.

Anil Kumar P
  • 541
  • 1
  • 9
  • 27

1 Answers1

1

The images that you use to build the containers that run on Kubernetes should contain everything that's needed to run the application.

When you create the JAR file for your application, this JAR should contain the dependencies. There are different ways to achieve this, using both Maven or Gradle. This is an example using Maven and its Apache Maven Assembly Plugin. This is another good user guide on how to achieve it.

Then, you need to create a container image that can run that JAR file, something like

FROM openjdk:8-jdk-alpine
EXPOSE 8080
WORKDIR /opt/app
CMD ["java", "-jar", "app.jar"]
COPY build/libs/app.jar /opt/app

Once this container image is published on a registry, whenever Kubernetes needs to schedule and create a container, it will just use that image: there is no need to re-compile the application and its dependencies.

Jose Armesto
  • 12,794
  • 8
  • 51
  • 56
  • Thanks a lot for your response. Mine is a Spring Boot application so i will prefer using "spring-boot-maven-plugin" for build as this ensures packaging everything into a single jar. Just to clarify, now that we have a single jar in place we can run create an image as we create for any other sample jar (lets say a "HelloWorld" example) right? No other additional steps to be mentioned in the image? The way how you have mentioned steps in the above comment section to create a container image. – Anil Kumar P Jan 13 '18 at 01:41
  • Exactly. You build the executable jar which can be ran by itself just by executing `java -jar app.jar`. Then you just need to copy it into the docker image and run it. – Jose Armesto Jan 13 '18 at 10:34
  • Thanks a lot for your responses once again – Anil Kumar P Jan 14 '18 at 01:45