How to Deal With Different JDK Versions and Vendors

DZone 's Guide to

How to Deal With Different JDK Versions and Vendors

All those JDK versions from all those JDK suppliers giving you headaches? Here's an open-source project to simplify things with Docker.

· Open Source Zone ·
Free Resource

We're going to talk about an open source project that includes a generator to build all needed scripts to create JDK and JDK/Maven Docker images.

Why Basic Docker Images Again?

Different people or organizations maintain the available "original" Docker images. This situation leads to small differences, and this was leading to different behaviors while using these images at runtime. Instead of hunting bugs, I decided to create a clean and straightforward solution. All Docker images are using the open source solution called Jabba to install the JDK.

A set of Docker images that are built precisely, in the same way, will help you to test your app against a matrix of JDK versions without handling the tiny details that are stealing your time.

Why Do We Need so Many Docker Images?

With the new release cycle that will bring us a new JDK every few months, we must decide how to deal with it in a project or product.

The generated Docker images help you test your application against different JDK versions and vendors. All images are created and pushed to the Docker Hub.

If you need a custom image, you can either use the provided images as a base or create your custom ones.

How to Use the JDK Docker Image Generator

In the following examples, I assume that Maven organizes the project. With Gradle, it should be the same, but maybe with different paths.

If you only need a JDK:

docker run \
       --rm \
       --name run \
       -v "$(pwd)":/usr/src/mymaven \
       -w /usr/src/mymaven \
       svenruppert/adopt:1.12.0-1 \
       java -jar target/myapp.jar

If you need Maven and a JDK:

docker run \
       --rm \
       --name compile \
       -v "$(pwd)":/usr/src/mymaven \
       -w /usr/src/mymaven \
       svenruppert/maven-3.6.1-adopt:1.12.0-1 \
       mvn clean install -Dmaven.test.skip=true

How to Generate

If you want to generate custom Dockerfiles by yourself, it would help if you edited the class Generator. Inside this class, you will find the templates as well.

This implementation is not super duper clean, but it works. Feel free to help me out and send a PR on GitHub!

The generated files, including the scripts for creating and pushing the images, are available under the directory _data. It will look like the following directory: https://github.com/svenruppert/docker-image-generator/tree/master/_data

You don't need to build these images by yourself, because all images are available in the official Docker registry.

Have a look at https://cloud.docker.com/u/svenruppert/.

Supported Versions and Vendors


  • OpenJDK
  • Oracle
  • Oracle - GraalVM
  • Amazon
  • IBM
  • Adopt-OpenJ9
  • Zulu
  • Liberica

JDK Versions (not from all vendors)

  • JDK 6
  • JDK 7
  • JDK 8
  • JDK 9
  • JDK 10
  • JDK 11
  • JDK 12
  • JDK 13

These images are updated every few days, depending on the pre-/release date of the projects.

docker images ,image generation ,java ,jdk ,open source ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}