OpenWebBeans is an implementation of the JSR-299. In this article I will give you a brief introduction to the OpenWebBeans.
OpenWebBeans has been under active development. OpenWebBeans have been developing as a small core code and including the other stuff as a plugin. There exist some plugins, these are
OpenWebBeans core is the implementation of the core functionality of the specification that does not contain any Java EE dependent technology. It is used for implementing the general dependency injection framework. It is valid for both Java Web Containers like Jetty, Tomcat or other Java EE containers like Geronimo, JBoss etc. Core code is located in the https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/webbeans-impl/ and https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/webbeans-api source folders in the SVN. WebBean API contains the general JSR-299 standart APIs. Module for the core implementation is called webbeans-impl module and api is called webbeans-api.
JPA plugin is used for implementing the Java Persistence API related stuff. Currently, this plugin injects the persistent context and persistent units of the JPA using @PersistentContext and @PersistentUnit annotations. In a full Java EE EJB containers (currently supports Apache OpenEJB) ,it provides the transactional entity managers. Core of the JPA related stuff is contained in the openwebbeans-jpa module. Transactional entity manager injection code is contained in the openwebbeans-geronimo module. SVN of the webbeans-jpa module is https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/webbeans-jpa and webbeans-geronimo is https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/webbeans-geronimo.
JMS plugin is used for implementing the JMS related functionality of the specification. You can inject any JMS Topic or Session related artifacts into the webbeans. (You can look at the section 3.7 of the specification for further information.). Code is contained in the webbeans-jms module. SVN of the module is https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/webbeans-jms.
JSF plugin is used for implementing the Java Server Faces(JSF) related functionality of the specification. Currently, it supports the ConversationScoped and EL Resolutions. You can use OpenWebBeans beans in your JSF based project as a backing/managed beans. JSF related moduie name is called webbeans-jsf. SVN of the webbeans-jsf module is https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/webbeans-jsf
EJB plugin is used for implementing the Enterprise Java Bean (EJB ) related functionality of the specification. This plugin is under the development and for the time being, there is no useful delivery artifacts. Because, it depends on the full EJB container that provides much of the requirement of the specification. It works with the EJB container tightly. We are planning to integrate the OpenEJB container via OpenWebBeans. It requires community help.
To use openwebbeans in your project, it requires to setup some basic configuration file, if you want to change its default configuration. It requires one configuration file, openwebbeans.properties in the META-INF/openwebbeans folder of the classpath. As a default, it contains the openwebbeans-default.properties file. In this file, there are some key-value pairs configurations. These are;
If you want to use specific OpenWebBeans plugin, you have to add the respective plugin jar into the classpath of your project. OpenWebBeans plugins are founded by the java.util.ServiceLoader strategy. Each plugin contains the META-INF/service/org.apache.webbeans.plugins.OpenWebBeansPlugin file that contains the implementation class of the respective plugin. At application startup, openwebbeans implementation runtime scans for all of the plugins and register them. For example, to use JMS plugin, add JMS plugin jar into the classpath. In this jar, there is an entry META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin file that contains the single entry, i.e "org.apache.webbeans.jms.plugin.OpenWebBeansJmsPlugin" that is implementation of the JMS plugin.
Currently, OpenWebBeans plugins are configured by the Java web projects via servlet context listener. You have to add below openwebbeans listener class into your web.xml file. If you would like to use JSF functionality, you also have to add JSF related configurations.
<listener> <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class> </listener>
JSF Related configuration. It configures the JSF filter for conversation management.
<filter> <filter-name>webbeans</filter-name> <filter-class>org.apache.webbeans.jsf.WebBeansJSFFilter</filter-class> </filter> <filter-mapping> <filter-name>webbeans</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping>
After you have done above steps, you are ready to write simple OpenWebBeans Project. There is an example module in the webbeans-guess module. SVN location is https://svn.apache.org/repos/asf/incubator/openwebbeans/trunk/samples/. You can deploy it into the Jetty container with mvn jetty:run. Also you can deploy it into the Java EE based containers.