<p>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?</p>

<p>should we have maven also as an image in the docker file?</p>

<p>Please explain in detail.</p>

<p>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.</p>

<p>So how do we maintain this in kubenetes.</p>

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

<p>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. <a href="https://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven">This is an example using Maven</a> and its Apache Maven Assembly Plugin. <a href="http://www.baeldung.com/executable-jar-with-maven" rel="nofollow noreferrer">This is another good user guide on how to achieve it</a>.</p>

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

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

<p>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.</p>
