Thursday, October 29, 2009

OpenWebBeans Injection Service in Embeddable Apache OpenEJB


In this post, I would like to give a simple tutorial on how to use the OpenWebBeans Dependency Injection service in an embeddable EJB container (Apache OpenEJB within Apache Tomcat 6.X).

This tutorial shows how to deploy and run sample web application that is located at "

Sample example simulates a simple telephone contact list. It has two main functionality

1* Add new telephone contact.
Adds a new telephone contact record into the database.

2* Show telephone contacts
Shows all contacts in a table.

Configuration Steps

1* If your system does not have Maven and Java Development Kit Version 6 (JDK 6).
Install maven and java 6 sdk into your system.
Configure your classpath so "mvn" and "java" commands can be run from any location.

2* Checkout OpenWebBeans development code from SVN trunk.

1.1)Checkout source code into the folder openwebbeans.
svn co openwebbeans

1.2)Compile and install it using maven command
cd openwebbeans;
mvn clean install;

If there is no errors, all jars are nstalled into respective "target" folders of the projects.

3* Download Tomcat 6.X version, (you can download Tomcat from

4* Download and configure OpenEJB. Look at the URL for OpenEJB installation steps.

5* Copy "atinject-api-1.0.0-incubating-SNAPSHOT.jar" from "openwebbeans/atinject-api/target" to Tomcat "/lib" folder.

6* Copy "openwebbeans-api-1.0.0-incubating-SNAPSHOT.jar" from "openwebbeans/webbeans-api/target" to Tomcat "/lib" folder.

After completing the above configuration steps successfully, our OpenEJB+Tomcat embeddable container is ready to use.

OpenWebBeans Configuration

To use the OpenWebBeans in an OpenEJB+Tomcat, it requires some configuration. OpenWebBeans has lots of configuration parameters. You can override all of them with an properties file. (You can look at for further details).

OpenWebBeans default properties can be overriden by using a "" file locating at the classpath of an application.

1* Create a "META-INF/openwebbeans/" in your web application classpath.(Its location will be "java/main/resources" in a mavenized web application.)

2* Add the following [key,value] pairs into the "" file. This enables EJB functionality and resource injection service in the web project, for example injection of @PersistenceContext, @PersistenceUnit, @Resource etc.

#use embedded openejb metadata discovery

#use resource service

Maven Based Web Application Configuration

Web Application Configuration

Create a web application using maven archetype. Look at the code in the "ejb-telephone" sample.

It uses "tomcat-maven-plugin" to deploy the web application into a running tomcat instance.

The web application directory structure look like this;
        openwebbeans --> OWB specific file
         persistence.xml --> JPA specific file
         faces-config.xml --> JSF Specific file

Compile And Deploy

Source code of the telephone application can be found at the "openwebbeans/samples/ejb-telephone".

Tomcat plugin uses http://localhost:8080/manager application to deploy war file
into your embeddable EJB Tomcat container. There must be an tomcat-users.xml
file in the "conf" directory of the Tomcat server that contains manager role and username.

Example tomcat-users.xml file

<role rolename="manager"/>
<user username="admin" password="" roles="manager"/>

>Start Tomcat server if not started
>cd Tomcat_Directory/bin;
> (or catalina.bat) run;
>mvn clean tomcat:deploy;

If everything goes well, hit the location in your favorite browser

Ejb Sample URL : http://localhost:8080/ejb-telephone.


Sunday, October 25, 2009

Using JSF2 Ajax with OpenWebBeans


I have created a simple JSF2 Ajax sample using OpenWebBeans. First update trunk and do following

Source Location is :

Run : mvn clean jetty:run

URL : http://localhost:8080/jsf2sample


Sunday, October 18, 2009

Using OpenWebBeans in Java SE

You can use OpenWebBeans dependency injection service in Java SE (for example Java Swing) project. New sample project is added to SVN trunk that shows how to use OpenWebBeans in Swing applications.

Source of the module is under "trunk/samples/standalone-sample".

Firstly you run mvn:install from the "trunk" to install/update necessary modules.


>> cd samples/standalone-sample;
>> mvn clean package;

This creates a jar in "target/standalone-sample.jar"
>> unjar this into any folder
>> java -jar standalone-sample-1.0.0-incubating-SNAPSHOT.jar Boot

It shows simple login screen :)


OpenWebBeans Pass JSR-330 TCK

After struggling some weird errors, we have finally passed JSR-330 TCK test suite.

You can check out sources from "/trunk/atinject-tck" module. It depends on new module "trunk/webbeans-porting" module.

>>cd atinject-tck;
>>mvn test;

Or from "trunk/"
>>mvn test -Pjsr330tck.

SVN Location :