The first post of my blog was about OSGi, a java technology that has gained some traction. As part of my OSGi education, I’ve been reading blogs, articles, and playing around with Apache Felix.
Currently I’m spending some of my free time working on an OSGi project as a learning tool. The code examples I’ve found have been nice but all do the same thing: a client bundle calls a service bundle in an Activator start method. End of story. This is great as a “Hello World” introduction, but I’d like to see how bundles operate in a way that reflect a real environment. Thus I’m trying to figure it out myself in a coding “live without a net” exercise. The project is an attempt to run a legacy enterprise javabean (EJB 2) in an OSGi Felix container. Yeah, I know EJB 3 is light years ahead but I sometimes have to work with the older spec at work. Besides, an EJB 2 OSGi bundle maybe just the demo needed to sell OSGi in my shop. 😉
I’ve found Apache’s OpenEjb project and started there as it advertises a port to OSGi. The core jars are bundles. Second, I used OpenEjb embedded in Tomcat web server at a Valtech EJB 3 course and walked away impressed. What follows is a way to get OpenEjb running in Felix.
Caveat Emptor: there may be a better/simpler/elegant way to do this. I’m an OSGi and Felix neophyte and your results may vary. BTW, this example was done on Windows XP.
Here’s how I did it:
1. I followed the Felix setup tutorial for Eclipse.
2. Add the <openejb home>/lib jar files to your Eclipse project’s classpath.
3. In your Eclipse project, click on the conf -> config.properties file.
4. Edit the org.osgi.framework.system.packages properties key by appending the following packages:
\ javax.annotation.security; \ javax.ejb; \ javax.ejb.spi; \ javax.interceptor; \ javax.management.j2ee; \ javax.persistence; \ javax.persistence.spi; \ javax.mail; \ javax.resource; \ javax.resource.spi; \ javax.resource.spi.endpoint; \ javax.resource.spi.work; \ javax.security.jacc; \ javax.wsdl; \ javax.wsdl.extensions.http; \ javax.wsdl.extensions.soap; \ javax.wsdl.factory; \ javax.wsdl.xml; \ org.apache.commons.cli; \ org.apache.geronimo.connector; \ org.apache.geronimo.connector.outbound; \ org.apache.geronimo.connector.outbound.connectionmanagerconfig; \ org.apache.geronimo.connector.outbound.connectiontracking; \ org.apache.geronimo.connector.work; \ org.apache.geronimo.transaction.log; \ org.apache.geronimo.transaction.manager; \ org.apache.log4j; \ org.apache.openjpa.event; \ org.apache.openjpa.persistence; \ org.apache.xbean.finder; version=3.4.0.r636442, \ org.apache.xbean.naming.context; version=3.3.0, \ org.apache.xbean.naming.reference; version=3.3.0, \ org.apache.xbean.recipe; version=3.4.0.r636442, \ org.codehaus.swizzle.stream; \ org.hibernate; \ org.hibernate.transaction; \ org.objectweb.asm; \ org.objectweb.asm.commons; \ sun.misc;
5. In the same config.properties file, look for the felix.auto.start.1 property. Append these OpenEjb bundle entries:
\ file:C:/<openejb home>/lib/openejb-jee-3.0.jar \ file:C:/<openejb home>/lib/openejb-loader-3.0.jar \ file:C:/<openejb home>/lib/openejb-javaagent-3.0.jar \ file:C:/<openejb home>/lib/openejb-core-3.0.jar \
Make sure to replace <openejb home> with the path to your OpenEjb installation.
6. Run your Felix Eclipse project per the instructions in the setup tutorial. After the Felix OSGi container initializes (hopefully successfully), type “ps” to list your installed bundles:
START LEVEL 1
ID State Level Name
[ 0] [Active ] [ 0] System Bundle (1.0.1)
[ 1] [Active ] [ 1] Apache Felix Shell Service (1.0.0)
[ 2] [Active ] [ 1] Apache Felix Shell TUI (1.0.0)
[ 3] [Active ] [ 1] Apache Felix Bundle Repository (1.0.0)
[ 4] [Active ] [ 1] openejb-jee (3.0)
[ 5] [Active ] [ 1] openejb-loader (3.0)
[ 6] [Active ] [ 1] openejb-javaagent (3.0)
[ 7] [Active ] [ 1] openejb-core (3.0)
Again, there may be a better way to do this but the above worked for me. Also, by adding the OpenEjb bundles to the felix.auto.start.1 property, I don’t have to continually restart those bundles when debugging my EJB 2 test bundle.
I can’t get my EJB 2 bundle to work with OpenEjb; my current issue is JNDI lookups. Once I figure that out (probably by using the OSGi service registry?), I may post my results if its not too much of a hack.
Update: The EasyBeans project has a tutorial on how to EJB and OSGi to play together.
Yo Darryl, this is off topic, but came across this article on Dzone: http://schalkneethling.alliedbridge.com/articles/still-think-proprietary-application-servers-are-the-best-option/
I wonder if we will ever ditch WebLogic and just go straight JBoss, seems as though we do that a little already. The interview talks about the next release of JBoss.
Laters,
-Houston
By the way, the code clippings in wordpress are formatted nice.
Houston,
Thanks for the JBoss link. The upcoming version of JBoss looks interesting. Now that it is a RedHat product, people leery of open source might have a change of heart. OSGi, AOP, REST, etc; so much to learn, too little time!
Shoot me an email this weekend if you need anything:
swengtx -at- gmail.com
Darryl