TomEE Embedded: a Spring Boot air without no EE features for business code

TomEE embedded is great but until now it needed a real application to deploy to at least get web features (was possible to deploy ejb modules from classpath but then you don’t get Servlet/WebSocket/… features).

Now you can do it simply calling deployClasspathAsWebApp() method!

Idea is simple: consider your classpath as a webapp. Once this is done you can:

  • Use @WebServlet, @WebFilter, @WebListener to register your web components (Servlet, Filter, ServletContextListener, HttpSessionListener…)
  • Use a ServletContainerInitializer to add programmatically web components
  • Use EJBs
  • Use CDI
  • Use JSP or any web resources (html, js, css…)…yes, you read correctly! Just put them in META-INF/resources
  • Use JAX-RS
  • Use WebSocket
  • Surely much more 😉

That’s one of the strengh of JavaEE: all is declarative so no need of redeclaring everything.

One demo can be found in TomEE source tree (a bit more complicated than your own code cause of its location in TomEE build):

If you want to use it just import as dependency org.apache.openejb:tomee-embedded:${tomee.snapshot} and use something like:

try (final Container container = new Container(new Configuration()).deployClasspathAsWebApp()) {
   // wait end of your program

Not that a main is also provided: org.apache.tomee.embedded.Main. Just use the new “-as-war” option.


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s