Home » Java » Enterprise Java » Microservices Series: MicroProfile and Apache TomEE

About Rajeev Hathi

Rajeev is a senior Java architect and developer. He has been designing and developing business applications for various companies (both product and services). He is co-author of the book titled 'Apache CXF Web Service Development' and shares his technical knowledge through his blog platform techorgan.com

Microservices Series: MicroProfile and Apache TomEE


MicroProfile is an initiative started in September 2016 by group of prominent vendors to build a Microservices architecture based on JEE platform. The mission is to optimize Enterprise Java for a Microservices architecture. The developers can make use of this architecture to build and develop Microservices applications in a standardized way using Enterprise Java platform.

The API building will be part of JCP program. MicroProfile is currently built on minimum footprint technology stack that includes JAX-RS, CDI and JSONP. More capabilities will be added going forward to build a more robust Microservices platform. The MicroProfile project is still a work in progress and its current release 1.2 is based on Eclipse Foundation under Apache 2.0 license. More information can be found at https://microprofile.io/

In this article, we will explore how to build and deploy a JEE based Microservices RESTful endpoint using one such MicroProfile runtime named Apache TomEE. Apache TomEE is the open source project that spawned the company Tomitribe which is one of the primary vendor contributing towards MicroProfile project.

Apache TomEE Microprofile

The example here will focus on building RESTful endpoint that will retrieve all customer expenses for a particular customer. Let’s quickly jump to the code:

public class ExpenseEndpoint {
	private Map<String, List<Expense>> expenses;
    public List<Expense> getExpenses(@PathParam("customerId") String customerId) throws Exception {
		expenses = loadExpenses();
        return expenses.get(customerId);

The above code is a simple JAX-RS ExpenseEndpoint endpoint that allows you to retrieve customer expenses based on id. We will build and publish this endpoint using Tomee runtime. The build narrative is part of POM file that uses TomEE maven plugin which enables us to build and deploy our ExpenseEndpoint microservice.


The above POM file makes use of exec goal of the package phase to build the jar file. The very fact that our endpoint will be an independent microservice that should be capable of being deployed and run in isolation, it needs to be embedded with a server runtime package, more as a fat jar. The other alternative can be to build as a docker image. To build our code, run the following command:

mvn package

The above maven command will run the exec goal of the TomEE maven plugin and build the fat jar. The fat jar will internally contain our mini web app runtime and this can be perceived as micro profile. To run our application, use the following command:

java -jar target\<buildname>-exec.jar

This will start the TomEE runtime, deploy our ExpenseEndpoint RESTful service. You can go to the browser and test the endpoint with the following URL: http://localhost:8080/expenses/C001 and it will throw you back the JSON string with all the expense details of the customer id C001.

As stated earlier MicroProfile is still a work in progress. The above was just one micro profile from Apache TomEE based on JAX-RS, JSON and CDI as a minimum API stack. MicroProfle project will continue its evolution through open collaboration and discussions within the community of developers. We have the larger message: JEE is here to stay!

Code for this article can be found at https://github.com/rhathi/microprofile

Reference: Microservices Series: MicroProfile and Apache TomEE from our JCG partner Rajeev Hathi at the TECH ORGAN blog.

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 ....


Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions


Notify of

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

Inline Feedbacks
View all comments