Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Getting started with OpenShift Java S2I

February 23, 2017
Thomas Qvarnström
Related topics:
ContainersJavaKubernetesMicroservices
Related products:
Red Hat OpenShift Container Platform

Share:

    Introduction

    The OpenShift Java S2I image, which allows you to automatically build and deploy your Java microservices, has just been released and is now publicly available. This article describes how to get started with the Java S2I container image, but first, let’s discuss why having a Java S2I image is so important.

    Why Java S2I?

    The Java S2I image enables developers to automatically build, deploy and run java applications on demand, in OpenShift Container Platform, by simply specifying the location of their application source code or compiled java binaries. In many cases, these java applications are bootable “fat jars” that include an embedded version of an application server and other frameworks. An example of such open source projects is Spring Boot, Eclipse Vert.x, and WildFly Swarm. Having a common Java S2I image that is designed specifically for OpenShift makes the development of bootable fat jars easier by including a number of useful features such as:

    • Simple yet flexible: The Java S2I image can handle complex build structures, but default it will assume that the JAR to run will be available in the /target directory after a successful build. If that is not the case you can use the environment variable ARTIFACT_DIR. Also if a build produces multiple JAR files (which is the case in the Eclipse Vert.x example used later in this article) then it’s possible to specify which JAR file to run using the environment variable JAVA_APP_JAR. However, in most cases, all you have to do is to point directly at you source repository and the Java S2I image will work.
    • Automatic JVM memory configuration: In OpenShift, resources may be limited by quotas, etc. If such a limitation is in place, the Java S2I image will automatically adopt the JVM memory settings so that the JVM doesn’t use more memory than it’s allowed to use which in turns helps to avoid OutOfMemory exceptions. This feature is enabled by default but can be disabled by setting a fixed value for the heap using -Xmx in the environment variable JAVA_OPTIONS.
    • Expose JMX statistics via Jolokia: By default, the Java S2I image will enable Jolokia which exposes JMX statistics and operations via HTTP. This enables more detailed monitoring capabilities of applications. This feature is enabled by default but can be disabled by setting the environment variable AB_JOLOKIA_OFF to true.
    • Reduce the container image size: To keep the size of the container image to a minimum it’s possible to have the Java S2I image delete any maven repo data before building the final image. This feature is disabled by default to support incremental builds. To enable the removal of maven artifacts from the final container image set the environment variable MAVEN_CLEAR_REPO to true.

    Getting started with Java S2I

    Below are step-by-step instructions that exemplify one way to use the Java S2I image.

    1. Create a new project or use an existing one.

    oc new-project myproject

     

    2. Before we start using the Java S2I image we need to tell OpenShift how to find it. This is done by creating an image stream. I’ve created an image stream definition here that you can download and use. To add the image stream to your project run the following command:

    oc create -f openjdk-s2i-imagestream.json

     

    3. Open the openshift console and navigate to the project you created and click on Add to Project.

    4. In the Browse Catalog window type openjdk in the search field.

    Browse Catalog window

    5. Click select and give the application a name and point to a git repo containing the application source code.

    For a WildFly Swarm example you can use:
    https://github.com/redhat-helloworld-msa/hola.git [1]

    For an Eclipse Vert.x example you can use:
    https://github.com/redhat-helloworld-msa/aloha.git [2]

    For a Spring Boot example you can use:
    https://github.com/redhat-helloworld-msa/ola.git

    6. Wait for the build to finish and click on the route (the URL in the upper right corner of the dashboard).

    7. For the WildFly example application, the swagger console should now be displayed.

    8. Try adding /api/hola to the address bar (or /api/ola for the Spring Boot example) and the outcome should be similar to the picture below.

    9. DONE

    I hope you have enjoyed this getting started with Java S2I guide.

    [1]=Please note that because of a known issue with WildFly Swarm and Jolokia you should also click on Show advanced … and add an environment variable to the Deployment Configuration with name AB_JOLOKIA_OFF and value true.

    [2]=The example project for Eclipse Vert.x produces two JAR files so we need to tell the Java S2I image which one to use by clicking on Show advanced … and add an environment variable to the Deployment Configuration with name JAVA_APP_JAR and value aloha-fat.jar.

    Last updated: August 20, 2023

    Recent Posts

    • Run Qwen3-Next on vLLM with Red Hat AI: A step-by-step guide

    • How to implement observability with Python and Llama Stack

    • Deploy a lightweight AI model with AI Inference Server containerization

    • vLLM Semantic Router: Improving efficiency in AI reasoning

    • Declaratively assigning DNS records to virtual machines

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue