days
-4
-2
hours
-2
-3
minutes
-4
-6
seconds
0
-7
search
JAX Developers Puzzle deadline approaching: Play for a chance to win a complimentary JAX London 2018 ticket!
It is simple, really

Meet Jib: Containerizing a Java application has never been easier

java
© Shutterstock / Oktyabr  

“Write once, run anywhere” has been the Java motto since forever! And what better way to achieve that if not with the use of containers? But we all know that containerizing Java applications is anything but simple. Jib is an open-source Java containerizer from Google that aspires to make a difference!

“Write once, run anywhere” (WORA), or sometimes “write once, run everywhere” (WORE), has been the motto that describes the cross-platform benefits of the Java language for ages and containers are bringing Java developers closer than ever to the realization of this type of workflow.

Don’t get me wrong though. Containerizing a Java application is no easy business and that was the main driver behind the creation of Jib.

Jib, an open-source Java containerizer created by Google lets Java developers build containers using the Java tools they are familiar with. It builds Docker and OCI images for your Java applications and is available as plugin for Maven and Gradle.

Jib was created in order to handle all the steps of packaging your application into a container image and it does not require you to write a Dockerfile or have docker installed since it is directly integrated into Maven and Gradle.

Let’s take a look at the visual representation of the build flow in comparison to Docker:

Docker build flow:

 

Jib build flow:

The goals behind Jib’s creation are threefold:

  • Be fast – Deploy your changes fast. Jib separates your application into multiple layers, splitting dependencies from classes. Now you don’t have to wait for Docker to rebuild your entire Java application – just deploy the layers that changed.
  • Be reproducible – Rebuilding your container image with the same contents always generates the same image. Never trigger an unnecessary update again.
  • Be daemonless – Reduce your CLI dependencies. Build your Docker image from within Maven or Gradle and push to any registry of your choice. No more writing Dockerfiles and calling docker build/push.

And how does it work, you ask?

According to its GitHub repo, whereas a Java application is traditionally built as a single image layer with the application JAR, “Jib’s build strategy separates the Java application into multiple layers for more granular incremental builds. When you change your code, only your changes are rebuilt, not your entire application. These layers, by default, are layered on top of a distroless base image.”

SEE ALSO: Nobody puts Java in a container

If you have more questions or comments like “But, I’m not a Java developer” or “I just want to set some JVM flags when running the image”, make sure to take a look at the FAQ section. 

Getting started

You can add Jib as a plugin for Maven and Gradle and it requires minimal configuration. Simply add the plugin to your build definition and configure the target image.

Jib on Maven

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <version>0.9.0</version>
  <configuration>
    <to>
      <image>gcr.io/my-project/image-built-with-jib</image>
    </to>
  </configuration>
</plugin>
# Builds to a container image registry.
$ mvn compile jib:build
# Builds to a Docker daemon.
$ mvn compile jib:dockerBuild

See the documentation for jib-maven-plugin.

Jib on Gradle

plugins {
  id 'com.google.cloud.tools.jib' version '0.9.0'
}
jib.to.image = 'gcr.io/my-project/image-built-with-jib'
# Builds to a container image registry.
$ gradle jib
# Builds to a Docker daemon.
$ gradle jibDockerBuild

See the documentation for jib-gradle-plugin.

You have to keep in mind, however, that if you are building to a private registry, you should make sure to configure Jib with credentials for your registry.

asap

Author
Eirini-Eleni Papadopoulou
Eirini-Eleni Papadopoulou is an assistant editor for JAXenter.com. Just finished her masters in Modern East Asian Studies and plans to continue with her old hobby that is computer science.

Leave a Reply

2 Comments on "Meet Jib: Containerizing a Java application has never been easier"

avatar
400
  Subscribe  
Notify of
Test
Guest
Gabriela Motroc
Admin

The link has already been included in the article above but thank you for making it more obvious