DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Getting Started With OpenShift Java S2I

Getting Started With OpenShift Java S2I

A very interesting update to the OpenShift PaaS allows you to quickly and easily handle your JAR deployment to OpenShift with great simplicity.

Thomas Qvarnström user avatar by
Thomas Qvarnström
·
Feb. 28, 17 · Tutorial
Like (6)
Save
Tweet
Share
7.14K Views

Join the DZone community and get the full member experience.

Join For Free

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 the 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. Examples of such open source projects are 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 by 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 tweak it using 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 your 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 turn, 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 show one way to use the Java S2I image.

Create a new project or use an existing one.

oc new-project myproject

 

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

 

Open the OpenShift console, navigate to the project you created, and click on Add to Project.

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

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.

  • 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 the name AB_JOLOKIA_OFF and setting the value to true.

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

  • 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 adding an environment variable to the Deployment Configuration with the name JAVA_APP_JAR and setting the value to aloha-fat.jar.

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

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

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

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.

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

Java (programming language) OpenShift Spring Framework application

Published at DZone with permission of Thomas Qvarnström, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Beginner's Guide to Back-End Development
  • RabbitMQ vs. Memphis.dev
  • Handling Automatic ID Generation in PostgreSQL With Node.js and Sequelize
  • Handling Virtual Threads

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: