OKD provides S2I enabled Java images for building and running Java applications. The Java S2I builder image assembles your application source with any required dependencies to create a new image containing your Java application. This resulting image can be run either by OKD or by Docker. This image is intended for use with Maven-based Java standalone projects (that are run via main class).


The current version supports JDK 1.7 and Maven 3.2.x projects.


To use this image, you can either access it directly from those image registries, or push it into your OKD Docker registry. Additionally, you can create an image stream that points to the image, either in your Docker registry or at the external location. Your OKD resources can then reference the ImageStream. You can find example ImageStream definitions for all the provided OKD images.

Build Process

S2I produces ready-to-run images by injecting source code into a container and letting the container prepare that source code for execution. It performs the following steps:

  1. Starts a container from the builder image.

  2. Downloads the application source.

  3. Streams the scripts and application sources into the builder image container.

  4. Runs the assemble script (from the builder image).

  5. Saves the final image.

See S2I Build Process for a detailed overview of the build process.


By default, the Java S2I builder image uses Maven to build the project with the following goals and options:

$ mvn package dependency:copy-dependencies -Popenshift -DskipTests -e

Based on these defaults, the image compiles the project and copies all the transitive dependencies into the output directory without running tests. Additionally, if the project has a profile named openshift, then it is activated for the build.

You can override these default goals and options by specifying the following environment variables:

Table 1. Java Environment Variables
Variable name Description Example


The arguments that are passed to the mvn command.

To package and also run tests:

s2i build -e "MAVEN_ARGS=clean test package" <git_repo_URL> fabric8/java-main <target_image_name>


Specifies the main class of the project. This can also be accomplished from within the .s2i/environment file as a Maven property inside the project (docker.env.Main).

Working with Multi-module Projects

If a Java project consists of multiple Maven modules, it can be useful to explicitly specify the output directory, or which modules to build.

To specify which modules to build in a multi-module project, along with all their module dependencies:

s2i build -e "MAVEN_ARGS=install -pl <my.groupId>:<my.artifactId> -am" <git_repo_URL> fabric8/java-main <target_image_name>

Specifying the directory where the Maven project outputs the artifacts helps the S2I build to pick them up. If unspecified, the default is the sources/target/ directory.

To specify the output directory and which modules to build in a multi-module project:

s2i build -e "OUTPUT_DIR=<path/to/myartifact/target>" -e "MAVEN_ARGS=install -pl <my.groupId>:<my.artifactId> -am" <git_repo_URL> fabric8/java-main <target_image_name>