Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      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
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java 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

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • 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

How to make Java programs cloud-ready: An incremental approach using Jakarta EE and MicroProfile

June 25, 2021
Mauro Vocale
Related topics:
JavaMicroservices
Related products:
Developer ToolsRed Hat JBoss Enterprise Application PlatformRed Hat OpenShift LocalRed Hat OpenShift Container Platform

Share:

    Modern enterprises are moving applications into the cloud, often using a microservices architecture. This presents a challenge for legacy applications that were designed for standalone, on-premises servers. These applications must be able to interact with other services that are tailored to the cloud along the lines of the twelve-factor app rules. Your applications should offer tracing, monitoring, and metrics to ensure availability and good performance. If you move Java applications to the cloud, you are likely to find their size and memory footprint burdensome, because instances have to be uploaded quickly and run on lean systems.

    Luckily, several tools exist to ease the transition of enterprise Java applications to the cloud. This four-part series takes you through the steps to make a Java application cloud-ready. All the tools are free and open source, and we'll run them on Red Hat JBoss Enterprise Application Platform (JBoss EAP) and Red Hat OpenShift Container Platform. Very little Java code needs to be added to the application; we will accomplish nearly everything through tooling and configuration files.

    Read the whole series:

    • Part 1: An incremental approach using Jakarta EE and MicroProfile

    • Part 2: Upgrade the legacy Java application to Jakarta EE

    • Part 3: Integrate MicroProfile services

    • Part 4: Optimize the runtime environment

    Java for the cloud and microservices

    Too many developers and architects associate Java EE and Jakarta EE only with monolithic applications and application servers. The monolithic applications are commonly seen as static, not easily updatable, and lacking a path where they can evolve to use the features implemented by a container architecture and cloud environments.

    In reality, several of the major Java frameworks are being used to build cloud applications, taking advantage of the evolution of Java specifications to support lighter-weight and distributed applications. Legacy applications can also be upgraded, as you will see in this series. The upgrade path rests on three community-driven specifications:

    • Jakarta EE: A specification that allows the evolution of Java applications for containers and the cloud.
    • MicroProfile: A set of packages providing tools that are valuable when developing for the cloud.
    • Galleon: A popular packaging framework that offers fine-grained control over the contents of an image running an application.

    Red Hat implements this set of specifications using JBoss EAP and OpenShift.

    To demonstrate how to upgrade a monolithic application using these technologies, I adapted a simple project named weather-app-eap, which is based on Java API for RESTful Web Services (JAX-RS) and Java Persistence API (JPA). The source code is taken from the GitHub page for the weather-app application, which is used in the O'Reilly Media Katacoda course Getting Started with JBoss EAP on OpenShift. I updated the code to run on top of JBoss EAP 7.2.9 and OpenShift 4.7.

    After that, I upgraded the application in three steps:

    • Moved it from Java EE to Jakarta EE, which sets the stage for the following transformations.
    • Inserted MicroProfile specifications to implement patterns needed by cloud applications.
    • Optimized the container runtime image to create a more efficient container.

    Each of these upgrades will be covered by one article in this series. In this first article, we will focus on setting up the example application for the demonstrations to come. In Part 2, we will upgrade the legacy Java application to Jakarta EE.

    Environment and source code

    The following components were used to develop the example application for this series:

    • Red Hat CodeReady Containers (if you need a local OpenShift instance) or an OpenShift installation (I used version 4.7)
    • JBoss EAP 7.3
    • JBoss EAP XP 2.0
    • Apache Maven 3.5.4
    • OpenJDK 11
    • Git 2.31.1

    The source code is available on my GitHub repository. To better follow the project's evolution, I created three tags for the three application versions:

    • Jakarta_EE_version
    • MicroProfile_version
    • Galleon_Runtime_version

    Get the demo application

    Your first step is to get the source code needed for the demonstration. Open a terminal, select a directory, and clone the Git repository using the following command:

    $ git clone https://github.com/mvocale/JBoss_EAP_cloud_ready.git

    Now, go to your project directory and switch to the Jakarta_EE_version tag, where I stored the code used to transform our Java EE 8 application into a Jakarta EE 8 application:

    $ git checkout tags/Jakarta_EE_version

    The repository contains two subprojects:

    • weather-app-eap: The project source code based on Java EE 8, that will run using JBoss EAP 7.2 and OpenShift 4.7. This subproject will remain the same throughout our journey.
    • weather-app-eap-cloud-ready: The source code that we will modify to make the Java EE 8 application cloud-ready.

    You can also find a shell script, deploy-openshift.sh, that contains all the instructions needed to install the components implemented on top of OpenShift. If you don’t want to perform every single step that I describe, you can establish a connection with CodeReady Containers or an OpenShift remote cluster and launch the application there.

    Deploy the application on OpenShift

    Now we will connect to OpenShift to deploy the application developed using Java EE 8 and JBoss EAP 7.2. If you decided to use Red Hat CodeReady Containers, start it and log in as a developer using the following commands:

    $ crc start
    $ oc login -u developer -p developer https://api.crc.testing:6443

    Otherwise, if you have an available OpenShift environment, log in as follows, replacing the $token and $server_url placeholders with the proper values:

    $ oc login --token=$token --server=$server_url

    Create the project that will host your application:

    $ oc new-project redhat-jboss-eap-cloud-ready-demo --display-name="Red Hat JBoss EAP Cloud Ready Demo"

    Create and configure the PostgreSQL database

    The application needs a database to store information; we will use PostgreSQL for this purpose. Create and configure the database next:

    1. Import the image containing the application:

      $ oc import-image rhel8/postgresql-12 --from=registry.redhat.io/rhel8/postgresql-12 --confirm
    2. Create the PostgreSQL application:

      $ oc new-app -e POSTGRESQL_USER=mauro \
        -ePOSTGRESQL_PASSWORD=secret \
        -ePOSTGRESQL_DATABASE=weather postgresql-12 \
        --name=weather-postgresql
    3. Add the PostgreSQL icon to your database:

      $ oc patch dc weather-postgresql --patch '{"metadata": { "labels": { "app.openshift.io/runtime": "postgresql" } } }'

    Import the JBoss EAP 7.2 OpenJDK 8 image

    Now, import the JBoss EAP 7.2 OpenJDK 8 image that we will use to deploy the traditional application:

    $ oc import-image jboss-eap-7/eap72-openshift --from=registry.access.redhat.com/jboss-eap-7/eap72-openshift --confirm

    Build and deploy the application

    Finally, build and deploy your application:

    1. Create a new build for the application:

      $ oc new-build eap72-openshift --binary=true --name=weather-app-eap
    2. Run the Maven build:

      $ cd weather-app-eap && mvn clean package
    3. Start the build for your application:

      $ oc start-build weather-app-eap --from-file=target/ROOT.war --wait
    4. Create the application:

      $ oc new-app weather-app-eap -e DB_SERVICE_PREFIX_MAPPING=weatherds-postgresql=DB \
       -e DB_JNDI=java:jboss/datasources/WeatherDS \
       -e DB_DATABASE=weather \
       -e DB_USERNAME=mauro \
       -e DB_PASSWORD=secret \
       -e DB_DRIVER=postgresql \
       -e DB_NONXA=true \
       -e DB_URL='jdbc:postgresql://$(WEATHER_POSTGRESQL_SERVICE_HOST):$(WEATHER_POSTGRESQL_SERVICE_PORT)/weather'
    5. Expose the route in order to test the application:

      $ oc expose svc weather-app-eap
    6. Add the JBoss EAP icon:

      $ oc patch dc weather-app-eap --patch '{"metadata": { "labels": { "app.openshift.io/runtime": "eap" } } }'

    Explore the application on OpenShift

    If you have successfully deployed the application, you can see it in the OpenShift console, as shown in Figure 1.

    The weather-app application and the database available in the OpenShift console.
    Figure 1: The weather-app application in the OpenShift console.

    Now, select the application from the topology view, at the bottom of the Resources tab, as shown in Figure 2.

    Use the route location on the Resources tab to access the application.
    Figure 2: Use the Routes location on the Resources tab to access data about the application.

    Click the link under Routes—>Location to view the application's output, as shown in Figure 3.

     

    weather-app application data
    Figure 3: Output from the weather app.

    Conclusion to Part 1

    We've gone through these steps to ensure that you can get the legacy Java application running. In the articles that follow, we'll perform part of the upgrade. At the end of each article, the application will be deployed and usable, just as it is now.

    Next up: Part 2: Upgrade the legacy Java application to Jakarta EE.

    Last updated: November 8, 2023

    Related Posts

    • Making Java programs cloud-ready, Part 2: Upgrade the legacy Java application to Jakarta EE

    • Jakarta EE: Multitenancy with JPA on WildFly, Part 1

    • Jakarta EE 8: The new era of Java EE explained

    • Quarkus: Modernize "helloworld" JBoss EAP quickstart, Part 1

    • Analyze monolithic Java applications in multiple workspaces with Red Hat's migration toolkit for applications

    Recent Posts

    • GuideLLM: Evaluate LLM deployments for real-world inference

    • Unleashing multimodal magic with RamaLama

    • Integrate Red Hat AI Inference Server & LangChain in agentic workflows

    • Streamline multi-cloud operations with Ansible and ServiceNow

    • Automate dynamic application security testing with RapiDAST

    What’s up next?

    Javascript Sandbox Activity

    Move your legacy Java application into a container and deploy it to Kubernetes in minutes using the Developer Sandbox for Red Hat OpenShift. Start exploring in the sandbox for free—no setup or configuration required.

    Try Java in the developer sandbox
    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

    Red Hat legal and privacy links

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

    Report a website issue