$ mvn package dependency:copy-dependencies -Popenshift -DskipTests -e
OpenShift Origin 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 OpenShift Origin or by Docker. This image is intended for use with Maven-based Java standalone projects (that are run via main class).
To use this image, you can either access it directly from those image registries, or push it into your OpenShift Origin 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 OpenShift Origin resources can then reference the ImageStream. You can find example ImageStream definitions for all the provided OpenShift Origin images.
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:
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). |
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>