TomEE 8 already supports CDI 2.0 and since Apache provides implementations for all Microprofile specifications there is just one last step to get TomEE being Microprofile 2.0.

To do that there are mainly two options:

  • Use TomEE Embedded and add geronimo-microprofile-aggregator pom as a dependency to grab the full stack
  • Use TomEE Maven Plugin to bundle a custom TomEE MP distro

This is this last option we'll investigate in this post.

The game, here, is to add all the Microprofile API and their implementations in the libs of the TomEE distribution:

<plugin>
  <groupId>org.apache.tomee.maven</groupId>
  <artifactId>tomee-maven-plugin</artifactId>
  <version>8.0.0-SNAPSHOT</version>
  <executions>
    <execution>
      <id>package-tomee-mp</id>
      <phase>package</phase>
      <goals>
        <goal>build</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <libs> <!-- MP 2.0 -->
      <!-- api -->
      <lib>org.eclipse.microprofile.config:microprofile-config-api:1.2.1</lib>
      <lib>org.eclipse.microprofile.fault-tolerance:microprofile-fault-tolerance-api:1.0</lib>
      <lib>org.eclipse.microprofile.jwt:microprofile-jwt-auth-api:1.1</lib>
      <lib>org.eclipse.microprofile.rest.client:microprofile-rest-client-api:1.0.1</lib>
      <lib>org.eclipse.microprofile.opentracing:microprofile-opentracing-api:1.1</lib>
      <lib>io.opentracing:opentracing-api:0.31.0</lib>
      <!-- impl -->
      <lib>org.apache.geronimo.config:geronimo-config-impl:1.2</lib>
      <lib>org.apache.geronimo.safeguard:safeguard-impl:1.0</lib>
      <lib>net.jodah:failsafe:1.0.4</lib>
      <lib>org.apache.geronimo:geronimo-jwt-auth:1.0.0</lib>
      <lib>org.apache.geronimo:geronimo-opentracing:1.0.0</lib>
      <lib>org.apache.cxf:cxf-rt-rs-mp-client:3.2.4</lib>
    </libs>
  </configuration>
</plugin>

Once done, you can run mvn package and you will find in target/<your artifactId>-<your version>.zip a Microprofile TomEE distribution.

Since this build will only work with TomEE snapshot (until 8.0.0 is released), you will have to add the following repositories in your pom:

<repositories>
  <repository>
    <id>asf.snapshots</id>
    <url>https://repository.apache.org/content/repositories/snapshots/</url>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </repository>
</repositories>
<pluginRepositories>
  <pluginRepository>
    <id>asf.snapshots</id>
    <url>https://repository.apache.org/content/repositories/snapshots/</url>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </pluginRepository>
</pluginRepositories>

Now you can add code to the project using Microprofile 2.0 and just run it nicely on this custom distribution. The nice thing is that it deploys quite easily in a docker image, you just have to run the standard Tomcat scripts :).

To develop against this distribution, you have to add in scope provided the API. If you don't want to manage all the API, you can use Geronimo aggregator pom as a shortcut:

<dependencies>
  <dependency>
    <groupId>org.apache.tomee</groupId>
    <artifactId>javaee-api</artifactId>
    <version>8.0-SNAPSHOT</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>org.apache.geronimo</groupId>
    <artifactId>geronimo-microprofile-aggregator</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <type>pom</type>
    <scope>provided</scope>
  </dependency>
</dependencies>

Happy Microprofile coding!

From the same author:

In the same category: