Little tip to help you to test JavaEE 7 in TomEE with TomEE Maven plugin.


Since JavaEE 7 is brand new TomEE is still JavaEE 6 but you can want to add to TomEE some JavaEE 7 features either upgrading some libraries (like BVal which has a Bean Validation 1.1 branch) or replacing some implementation by another one.

Replacing the implementation is generally easy since you can add it either in your application or in the container through <libs> tag of tomee-maven-plugin BUT here you also need to replace the API (= upgrading the JavaEE 6 provided one to a JavaEE 7 one).

TomEE is coming with a bundle API jar (javaee-api) so how to do so?

It fact it is pretty trivial, when we built the bundle jar we built an assembly with all included jars too so you basically just need to ask the tomee-maven-plugin to remove the javaee-api jar, then to extract the assembly of geronimo spec jars. It can be done adding two lines to <libs>:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.openejb.maven</groupId>
      <artifactId>tomee-maven-plugin</artifactId>
      <version>1.6.0-SNAPSHOT</version>
      <configuration>
        <libs>
          <lib>remove:javaee-api</lib>
          <lib>unzip:org.apache.openejb:javaee-api:6.0-5:zip</lib>
        </libs>
      </configuration>
    </plugin>
  </plugins>
</build>

Easy isn’t it? ūüėČ

You can even go further, if you want to replace CDI API (from version 1.0 to 1.1) to use openwebbeans cdi11 module (pretty new and unstable ATM). You can of course replace the unzip line by the list of all geronimo API jars but it will be very verbose…An alternative will be to use the fact <libs> is a list and commands are executed sequentially, so just ask the plugin to remove the cdi 1.0 API after having unpacked the javaee-api zip and finally add the API you want:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.openejb.maven</groupId>
      <artifactId>tomee-maven-plugin</artifactId>
      <version>1.6.0-SNAPSHOT</version>
      <configuration>
        <libs>
          <lib>remove:javaee-api</lib>
          <lib>unzip:org.apache.openejb:javaee-api:6.0-5:zip</lib>
          <lib>remove:geronimo-jcdi_1.0_spec-1.0</lib>
          <lib>javax.enterprise:cdi-api:1.1</lib>
        </libs>
      </configuration>
    </plugin>
  </plugins>
</build>
Advertisements

2 thoughts on “Little tip to help you to test JavaEE 7 in TomEE with TomEE Maven plugin.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s