Run Java EE 8 apps on Oracle Cloud with Payara Micro

This blog will demonstrate how to build and deploy a Java EE 8 microservice on Oracle Cloud

  • Oracle Application Container Cloud is used as the runtime platform
  • The application is in the form of a simple Java EE WAR file which is packaged along with Payara Micro 5 (alpha release) container (bring-your-own-runtime). More on the release announcement here

This makes it easy to leverage the platform enhancements in Java EE 8 and run cloud native, lightweight and scalable apps in the cloud

In case you haven’t heard of Payara Micro, you can start by exploring its website

Java EE 8 specifications

As with every platform release, Java EE 8 comprises of new specifications as well as enhancements to many of the existing components. The sample application in the blog demonstrates the following features in the below mentioned specifications

  • Context and Dependency Injection (CDI) 2.0 — asynchronous events producer and consumer
  • JAX-RS 2.1 — Server Sent Events feature to be specific
  • JSON-B 1.0 (JSON Binding) integration with JAX-RS

Sample application

Here is a high level flow

overview of the solution
  • The service consists of a timer component which emits events at regular intervals.
  • This is consumed by another component which makes the events available over Server Sent Events (SSE) — any (SSE) client (including your browser or a JavaScript app) can hook up to receive these
the project is available on Github for you to grok further

Let’s look at some of the implementation details

What’s going on ?

Here is a summary of the Java EE 8 specs and their respective components

Scheduled (event producer) component

  • An @ApplicationScoped CDI bean produces asynchronous CDI events (new in CDI 2.0 with Java EE 8) — this is done using Event.fireAsync()
  • The ManagedExecutorService (from the Java EE Concurrency utilities spec) thread pool is used to execute the timer/scheduler
  • These CDI events are qualified (using a custom @Qualifier)

Server Sent Events component

Exposes an endpoint for clients to register/subscribe to events

Broadcasting component

  • Wrapper over a
  • Handles client registration and maintains active/connected clients
  • Asynchronously receives CDI events (using @ObservesAsync ) and broadcasts it to connected clients
  • the POJO to JSON (for the client) is handled by the inbuilt JAX-RS and JSON-B integration

Build & deployment

Let’s build and push our application using the cloud


The build process creates the following artifacts in the target directory

  • WAR — our Java EE app
  • JAR — this is the Payara Micro 5 container itself
  • ZIP — this is the deployable artifact which consists of the the WAR and JAR (bring-your-own-runtime)
Build artifacts

Deployment descriptors

A quick word on deployment descriptors — you can read the detailed documentation here (these are just metadata files)

  • manifest.json — defines how our application will start. In this case we use the Payara Micro runtime to run our WAR file
“command”:”java -jar payara-micro.jar --deploy accs-javaee8.war --port $PORT”,
“notes”:”Java EE 8 application on ACCS”
  • deployment.json — we define the topology of our application. In this case we are deploying 1 instance with 1 GB memory (you are free to choose the desired shape & size)

Time to deploy our Java EE 8 application to the cloud!

Push to cloud

With Oracle Application Container Cloud, you have multiple options in terms of deploying your applications. This blog will leverage PSM CLI which is a powerful command line interface for managing Oracle Cloud services

other deployment options include REST API, Oracle Developer Cloud and of course the console/UI
  • Download and setup PSM CLI on your machine (using psm setup) — details here
  • cd <code_directory>
  • psm accs push -n accsjavaee8 -r java -s hourly -m manifest.json -d deployment.json -p target/

Once executed, an asynchronous process is kicked off and the CLI returns its Job ID for you to track the application creation

Pushing an ACCS application using PSM CLI
Check out the PSM CLI on Docker blog here

Check your application

Your application should be deployed on Oracle Application Container Cloud and its URL will be available for you to access it

Java EE 8 app on Oracle App Container Cloud

Testing the application

Simple — use your browser to navigate to the application URL

e.g. https://accsjavaee8-<id_domain>

Please note that the URL will be different based on your identity domain

What you need to do next should be self explanatory :-)

one click away….

You should see a continuous stream of (SSE) events — the (SSE) id is a (long) time stamp and (SSE) data is a JSON payload of the TickTock POJO

Stream of SSE events…

That’s all for this blog..

Don’t forget to check out…

Further reading


The views expressed in this post are my own and do not necessarily reflect the views of Oracle.
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.