Skip to content

Latest commit

 

History

History

hollow-uber-jar

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Jakarta EE Hollow Uber Jars with Docker

This demo shows using Java/Jakarta EE hollow uber jars with Docker repositories, layering, and caching. This is by far the most efficient way of deploying Java/Jakarta EE applications on Docker.

Start the Database with Docker

The first step to getting the application running is getting the database up. Please follow the instructions below to get the database running.

  • Ensure that all running Docker containers are shut down. You may want to do this by restarting Docker. The demo depends on containers started in the exact order as below (this will be less of a problem when we start using Kubernetes).
  • Make sure Docker is running. Open a console.
  • Enter the following command and wait for the database to come up fully.
docker run -it --rm -e POSTGRES_HOST_AUTH_METHOD=trust --name jakartaee-cafe-db -v pgdata:/var/lib/postgresql/data -p 5432:5432 postgres
  • The database is now ready (to stop it, simply press Control-C after the Jakarta EE application is shutdown).

Start the Application with Docker

The next step is to get the application up and running. Follow the steps below to do so.

  • Open Eclipse.

  • Do a full build of the jakartaee-cafe application via Maven by going to Right click the application -> Run As -> Maven install.

  • Browse to where you have this repository code in your file system. You will now need to copy the war file to where we will build the Docker image. You will find the war file under jakartaee/jakartaee-cafe/target. Copy the war file to hollow-uber-jar/.

  • You should explore the Dockerfile in this directory used to build the Docker image. It starts from the minimalist websphere-liberty:kernel image, adds exactly the features that are needed for the application, adds the jakartaee-cafe.war from the current directory in to the dropins directory, copies the PostgreSQL driver postgresql-42.2.18.jar into the shared/resources directory and replaces the defaultServer configuration file server.xml.

  • Notice how minimal and specific the server.xml file is. This produces the minimum footprint and startup time for this application.

  • Open a console. Build a Docker image tagged jakartaee-cafe navigating to the hollow-uber-jar/ directory as context and issuing the command:

     docker build -t jakartaee-cafe .
    
  • To run the newly built image, use the command:

     docker run -it --rm -p 9080:9080 jakartaee-cafe
    
  • Wait for WebSphere Liberty to start and the application to deploy sucessfully (to stop the application and Liberty, simply press Control-C).

  • Once the application starts, you can test the REST service at the URL: http://localhost:9080/jakartaee-cafe/rest/coffees or via the JSF client at http://localhost:9080/jakartaee-cafe/index.xhtml.