OpenShift Online provides an S2I builder image for building Java applications. This builder image takes your application source or binary artifacts, builds the source using Maven (if source was provided), and assembles the artifacts with any required dependencies to create a new, ready-to-run image containing your Java application. This resulting image can be run on OpenShift Online or run directly with Docker.

The builder image is intended for use with Maven-based Java standalone projects that are run via main class.


The current version of the Java S2I builder image supports OpenJDK 1.8, Jolokia 1.3.5, and Maven 3.3.9-2.8.


The RHEL 7 image is available through the Red Hat Registry:

$ docker pull registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift

You can use the image through the redhat-openjdk18-openshift image stream.


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

mvn -Dmaven.repo.local=/tmp/artifacts/m2 -s /tmp/artifacts/configuration/settings.xml -e -Popenshift -DskipTests -Dcom.redhat.xpaas.repo.redhatga -Dfabric8.skip=true package -Djava.net.preferIPv4Stack=true

Based on these defaults, the builder 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


The relative path to the target where JAR files are created for multi-module builds.


The main class to use as the argument to Java. This can also be specified in the .s2i/environment file as a Maven property inside the project (docker.env.Main).


The arguments that are passed to the mvn command.

Building and Deploying Java Applications

The same S2I builder image can be used to build a Java application from source or from binary artifacts.

Building and Deploying from Source

The Java S2I builder image can be used to build an application from source by running oc new-app against a source repository:

$ oc new-app redhat-openjdk18-openshift~https://github.com/jboss-openshift/openshift-quickstarts --context-dir=undertow-servlet

By default, tests are not run. To build an application and run tests as part of the build, override the default MAVEN_ARGS, as in the following command:

$ oc new-app redhat-openjdk18-openshift~<git_repo_URL> --context-dir=<context-dir> --build-env='MAVEN_ARGS=-e -Popenshift -Dcom.redhat.xpaas.repo.redhatga package'

If a Java project consists of multiple Maven modules, it can be useful to explicitly specify the artifact output directory. Specifying the directory where the Maven project outputs the artifacts enables the S2I build to pick them up.

To specify the modules to build and the artifact output directory, use the following command:

$ oc new-app redhat-openjdk18-openshift~<git_repo_URL> --context-dir=<context-dir> --build-env='ARTIFACT_DIR=relative/path/to/artifacts/dir' --build-env='MAVEN_ARGS=install -pl <groupId>:<artifactId> -am'

Building and Deploying from Binary Artifacts

The Java S2I builder image can be used to build an application using binary artifacts that you provide. To do so, first create a new binary build using the oc new-build command:

$ oc new-build --name=<application-name> redhat-openjdk18-openshift --binary=true

Next, start a build using the oc start-build command, specifying the path to the binary artifacts on your local machine:

$ oc start-build <application-name> --from-dir=/path/to/artifacts --follow

Finally, use the oc new-app command to create an application:

$ oc new-app <application-name>

Additional Information and Examples