Tomcat + Java EE = TomEE, the Java Enterprise Edition of Tomcat. With TomEE you get Tomcat with CDI added and integrated and ready to go!

import javax.annotation.Resource;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyServlet extends HttpServlet {

    @Inject
    private Car car;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        car.drive();

    }
}

Where Car could be any POJO with a no-arg constructor. Additionally it's quite easy to create a factory to create the car you want injected. Simply do as follows:

import javax.enterprise.inject.Produces;

public class AssemblyLine {

    @Produces
    public Car createFancyCar() {
        return new Car("Ferrari", "458 Italia", 2012);
    }
}

So when will the Car be created? In the above it will be created when MyServlet is created. If you annotate createFancyCar with @RequestScoped it will be created once per http request and shared by everyone in the request. If you annotate createFancyCar with @SessionScoped it will be created once per HttpSession and shared by everyone in the same session. So no more repeatedly putting and getting into the HttpSession by hand, just let the container do it!

No need to add even a single library! To make the above work all you need is a META-INF/beans.xml file in your webapp like the following:

<beans/>

Any jar in your webapp with the above will automatically be CDI enabled and all those beans can be injected with @Inject with no need to make them EJBs or third party frameworks.

All this is setup and ready to go! Spend your time learning and having fun and writing your app, don't spend it chasing down libraries and integrating things the hard way.

Download TomEE and you're minutes away from having fun with CDI on Tomcat.

Apache TomEE, pronounced "Tommy", is an all-Apache Java EE 6 Web Profile certified stack where Apache Tomcat is top dog. Apache TomEE is assembled from a vanilla Apache Tomcat zip file. We start with Apache Tomcat, add our jars and zip up the rest. The result is Tomcat with added EE features - TomEE.

Download Apache TomEE Now »  and get started today!

TomEE

The Web Profile version of TomEE contains

  • CDI - Apache OpenWebBeans
  • EJB - Apache OpenEJB
  • JPA - Apache OpenJPA
  • JSF - Apache MyFaces
  • JSP - Apache Tomcat
  • JSTL - Apache Tomcat
  • JTA - Apache Geronimo Transaction
  • Servlet - Apache Tomcat
  • Javamail - Apache Geronimo JavaMail
  • Bean Validation - Apache BVal

TomEE+

The TomEE Plus distribution adds the following:

  • JAX-RS - Apache CXF
  • JAX-WS - Apache CXF
  • JMS - Apache ActiveMQ
  • Connector - Apache Geronimo Connector

Goal

Simple, Get more from Tomcat without giving anything up.

Focuses

Some core focuses guide the integration:

The desire to beef up Tomcat installations has persisted despite the existence of full-blown app servers, many of which include Tomcat in some truncated and stripped-down form. Not TomEE.

Under the Covers

Apache TomEE is assembled from a vanilla Apache Tomcat zip file. No picking and choosing individual parts of Tomcat and building a "new" server leveraging Tomcat. We start with Tomcat, add our jars and zip up the rest. The result is Tomcat with added EE features, TomEE.

Tomcat provides plenty of hooks for filling out parts of its lifecycle. We leverage them all to fill the gaps. The result is a whole lotta sharing!

Servlets now get access to JPA and Transactions, EJBs get access to Tomcat provided Security. Any Tomcat provided resources, say from a context.xml, can be looked up or injected by any managed component in the system.

Keep it Tight, Keep it Simple

There's a definite "less is more" philosophy in Apache TomEE. It's too easy to go too far when developing an app server. The result is usually a slow to start, memory hogging, beast. We're not here to create an ultra flexible, super powerful, infinitely composable, be anything to anyone platform. We're here to deliver Java EE 6 Web Profile in the simplest way possible.

If you were to imagine taking a plain Tomcat install and integrating the missing components in the most direct and to-the-point style possible, you'd end up with TomEE. The result speaks for itself:

History

In Apache TomEE's previous life, it was simply known as the OpenEJB+Tomcat integration. That description was always quite misleading. For one, there's incredible benefit even if EJB is never used.

Quite simply, EJB as a technology integrates with the most number of specs than any other spec. It touches JMS, Web Services, Connectors, Servlets (EJB Web Services are still driven by Servlets!), JPA, JDBC, Transactions, Security. Integrating with all these technologies takes time and expertise and in the end has very little to do with EJB specifically. To apply this all to Tomcat and leverage it all from a simple Servlet is a natural extension and the reason most app servers started out as EJB servers.

Whereas most app servers pluck Tomcat out of its environment, Apache OpenEJB has always existed as an embeddable container focused on being as tiny and invisible as possible. The natural extension of this is to embed the "EE" into Tomcat, rather than the other way around.

But in the end, it is not about EJB. It's about the other guys: ActiveMQ, CXF, MyFaces, OpenJPA, OpenWebBeans, and of course Tomcat! So out with OpenEJB+Tomcat and in with Apache TomEE!