Coming Up for Air

Getting Started with Eclipse MicroProfile, Part 5: TomEE

Thursday, October 18, 2018 |

In this installment of our series, we’re going to take a look at the last of what I think of as the more traditional, app-server-based/-spawned implementations, TomEE. TomEE is a fully Java EE-enabled distribution of the venerable workhorse Tomcat, and comes with support for creating MicroProfile applications, so let’s see what that looks like.

This should come as no surprise at this point, but setting up a TomEE-based project requires little effort. We start by adding these dependencies to our web project:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<properties>
    <tomee.version>7.1.0</tomee.version>
</properties>

<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>common</artifactId>
        <version>${project.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tomee</groupId>
        <artifactId>arquillian-tomee-embedded</artifactId>
        <version>${tomee.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomee</groupId>
        <artifactId>tomee-jaxrs</artifactId>
        <version>${tomee.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Notice that the only compile/runtime dependency is our shared code. The rest is for testing.

We’ll need a plugin to bundle our application:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomee.maven</groupId>
            <artifactId>tomee-maven-plugin</artifactId>
            <version>${tomee.version}</version>
            <configuration>
                <tomeeClassifier>webprofile</tomeeClassifier>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <context>ROOT</context>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The exec goal will build our uberjar, and we set the context to ROOT so that our application is deployed on the root context.

1
2
3
4
5
6
7
8
# mvn install
...
# java -jar target/tomee-1.0-SNAPSHOT-exec.jar
...
# curl http://localhost:8080
Hello, world
# curl http://localhost:8080/?name=TomEE
Hello, TomEE

We already have our Arquillian dependencies added, and there are no additional configuration files needed for this very basic case, so we can run our tests via mvn test as we’ve seen many times already.

As Emeril would say, BAM! We’re all done. Things get more complicated as the project gets more complicated, but I’ll try to discuss that in our wrap up.

Stay tuned for an implementation of a different color next time when we look at Hammock.

You can find the source for the whole project here, and for this part here.

Search

    Quotes

    Sample quote

    Quote source

    About

    My name is Jason Lee. I am a software developer living in the middle of Oklahoma. I’ve been a professional developer since 1997, using a variety of languages, including Java, Javascript, PHP, Python, Delphi, and even a bit of C#. I currently work for Red Hat on the WildFly/EAP team, where, among other things, I maintain integrations for some MicroProfile specs, OpenTelemetry, Micrometer, Jakarta Faces, and Bean Validation. (Full resume here. LinkedIn profile)

    I am the president of the Oklahoma City JUG, and an occasional speaker at the JUG and a variety of technical conferences.

    On the personal side, I’m active in my church, and enjoy bass guitar, running, fishing, and a variety of martial arts. I’m also married to a beautiful woman, and have two boys, who, thankfully, look like their mother.

    My Links

    Publications