Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using Apache OpenWebBeans with Apache Tomcat

DZone's Guide to

Using Apache OpenWebBeans with Apache Tomcat

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

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

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}