Adding OpenWebBeans to your Servlet Container project

OpenWebBeans in a great match for web-apps and should work well for your favorite Servlet Containers such as Jetty or Tomcat. To add OpenWebBeans to your Servlet Container project you need to take the following steps.

  1. Add dependencies accordingly to instructions below.
  2. In some cases add org.apache.webbeans.servlet.WebBeansConfigurationListener to web.xml as a listener
  3. Done! Congratulations.

Adding required jars and plugins to your project

You can add OpenWebBeans to your project manually by adding jars or with Apache Maven. How to download is explained here: download page. The binary distributions include all the jars you need and the download page lists all the maven dependencies. But since OpenWebBeans is modular you should read below so you know what to add.

API jars

Several API bundles exists for java EE and they are mostly compatible with OpenWebBeans. If you already include one of these you might not need any api jars. CDI and thus OpenWebBeans depends on the following four apis:

You will only reference these API:s in your own project. This way your project will stay CDI vendor neutral. A typical use case would be to add all four of the above to your parent-pom or your core module.

Required

For Servlet Container projects such as Tomcat and Jetty you always start with:

Plugins

The following plugins are very useful if you need JSF, expression language (el) etc. Add accordingly to your needs.

When to use respective plugin

If the project uses Expression Language add EL plugin accordingly to your version. This is required for using EL.


For JSF support add JSF plugin accordingly to your version of JSF. This plugin is required for JSF support and do not forget the include the EL-plugin explained above.

If the project uses Tomcat 6 or Tomcat 7 you can add the respective plugin. This is not required but enables injection in Servlets and Filters. Note that Tomcat7 should be read as Tomcat7+ thus it works perfectly fine with Tomcat 8.

Bootstrapping OpenWebBeans

Simply put the following listener in web.xml:

    <listener>
        <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
    </listener>

This is not required if you use Tomcat and added the corresponding Tomcat plugin because in that case it's managed by the plugin.

From here you might want to look at our samples selection: samples.