Home » DevOps » Dockerized Java EE 8 applications with GlassFish 5.0

About Sebastian Daschner

Sebastian Daschner
Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.

Dockerized Java EE 8 applications with GlassFish 5.0

GlassFish 5.0 represents the reference implementation of Java EE 8. We can dockerize Java EE 8 applications by using a GlassFish base image, such as the official oracle/glassfish.

The Dockerfile of a zero-dependency Java EE 8 application looks like follows:

FROM oracle/glassfish:5.0

COPY target/application.war $GLASSFISH_HOME/glassfish/domains/domain1/autodeploy/

A Docker container of that image starts the application server and auto-deploys our application.

application.war is packaged a thin WAR deployment artifact, what speeds up build, publishing and deployment times. The WAR file comprises only application-specific classes, no implementation-specific JAR files. If needed, any dependencies are added on top of the base image — before the actual application.

Imagine, we want to add the Prometheus Java API:

FROM oracle/glassfish:5.0

ENV GLASSFISH_LIB=$GLASSFISH_HOME/glassfish/domains/domain1/lib/ext/

# add Prometheus Java API
COPY .../simpleclient-0.0.26.jar $GLASSFISH_LIB
COPY .../simpleclient_common-0.0.26.jar $GLASSFISH_LIB

COPY target/application.war $GLASSFISH_HOME/glassfish/domains/domain1/autodeploy/

The application can already use Java EE 8 standards such as JSON-B. The provided dependency is javax:javaee-api:8.0 — same as the Java EE 7 API with incremented version number.

To see a full example that uses Prometheus, please see Prometheus with Java EE. That example can also run on Java EE 8 and GlassFish 5 by updating the API version to 8.0 and the Docker base image to oracle/glassfish.

Have fun developing Java EE 8 applications for Docker!

Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java:

Success! Now check your email to confirm your subscription.

Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: Dockerized Java EE 8 applications with GlassFish 5.0

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of