My name is Gurkan Erdogdu and I am the CTO of the MechSoft Mechanical and Software Solutions. I have been active in the Java and Java EE platform more than 10 years. Strong supporter for the Free and Open Source Software, and actively participating within the Open Source based foundations like, Apache Software Foundation, JBoss, and recently Open Web Foundation. I am the member of the Apache Software Foundation and Open Web Foundation. Writing blog at gurkanerdogdu@blogspot.com. Gurkan has posted 24 posts at DZone. View Full User Profile

Using Apache OpenWebBeans with Apache Tomcat

07.29.2010
| 9623 views |
  • submit to reddit

This article is about how to configure Apache Tomcat 6 or 7 to use OpenWebBeans based dependency injection.

What is Apache  OpenWebBeans?

OpenWebBeans is an ASL 2.0-licensed implementation of the JSR-299, Contexts and Dependency Injection for the Java EE platform. Project's web page can be found at, "http://openwebbeans.apache.org"

 Requirements

Let's says that you have unzipped/untar OpenWebBeans into directroy /owb/ and Tomcat to /tomcat/. You have to copy some libraries to tomcat lib/ folder,

  • Copy /owb/api/geronimo-atinject_1.0_spec-1.0.jar to /tomcat/lib
  • Copy /owb/api/geronimo-jcdi_1.0_spec-1.0.jar to /tomcat/lib
  • Download geronimo-interceptor_1.1_spec-1.0.jar from  http://tiny.cc/4exgy and put into /tomcat/lib
  • Copy /owb/spi/openwebbeans-spi-1.0.0-alpha-1.jar to /tomcat/lib
  • Copy /owb/plugins/openwebbeans-tomcat6-1.0.0-alpha-1.jar to /tomcat/lib (For Tomcat 6)
  • Copy /owb/plugins/openwebbeans-tomcat7-1.0.0-alpha-1.jar to /tomcat/lib/ (For Tomcat 7)
  • Open /tomcat/conf/server.xml, add lifecycle listener as follows under "server" element
<Listener className="org.apache.webbeans.web.tomcat.ContextLifecycleListener" />

That is it! Configuration is ready to deploy your next JSR-299 Web Application to Apache Tomcat.

Sample Applications

Look at OWB SVN for Tomcat samples,

Using Maven

If you wish to use OpenWebBeans with Maven, just put the following entries to your  web application pom.xml for Tomcat 6,

    <dependencies>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>1.0.0-alpha-1</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.1_spec</artifactId>
<version>1.0</version>
</dependency>


<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>1.0.0-alpha-1</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
<scope>provided</scope>
<version>1.2</version>
</dependency>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-ee-common</artifactId>
<version>1.0.0-alpha-1</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.0_spec</artifactId>
<scope>provided</scope>
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<scope>provided</scope>
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
<version>1.0.0-alpha-1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-el10</artifactId>
<version>1.0.0-alpha-1</version>
</dependency>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-resource</artifactId>
<version>1.0.0-alpha-1</version>
</dependency>

</dependencies>

 

For Tomcat 7 maven configuration,

    <dependencies>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>1.0.0-alpha-1</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.1_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>


<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>1.0.0-alpha-1</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-ee-common</artifactId>
<version>1.0.0-alpha-1</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.0_spec</artifactId>
<scope>provided</scope>
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<scope>provided</scope>
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
<version>1.0.0-alpha-1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-resource</artifactId>
<version>1.0.0-alpha-1</version>
</dependency>


</dependencies>

  That is it!

   Enjoy!

OpenWebBeans User and Development Mailing Lists

Please mail to the user mailing list about any questions or advice
about the OpenWebBeans.

User Mailing List : [users@openwebbeans.apache.org]

You can also join the discussions happening in the dev list

Dev Mailing List  : [dev@openwebbeans.apache.org]

OpenWebBeans JIRA Page
Please logs bugs into the "https://issues.apache.org/jira/browse/OWB".

OpenWebBeans Web Page
You can reach the OpenWebBeans web page at, http://openwebbeans.apache.org
 

Gurkan Erdogdu

ASF Member,http://apache.org

PMC Chair, Apache OpenWebBeans

CTO, MechSoft Mechanical and Software Solutions, http://www.mechsoft.com.tr

Published at DZone with permission of its author, Gurkan Erdogdu.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Joanna Duff replied on Wed, 2010/08/11 - 3:08pm

Would love for you to check out tomcatexpert.com and contribute to the Enterprise Tomcat Community!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.