JBoss have come up with an embeddable version of their EJB3 implementation. An alpha release is available for download.
I downloaded it and played around with the embedded example from the tutorial.
Here’s what I did:
- once you’ve downloaded and unzipped the alpha release (I tested with jboss-EJB-3.0_Embeddable_ALPHA_5.zip), go to the
docs/embedded-tutorial/embedded-war directory and build it (just type ant). - unjar the war file in docs/embedded-tutorial/embedded-war/build/standalone.war to your $jetty.home/webapps directory.
- move all of the jars in $jetty.home/webapps/standalone/WEB-INF/lib except for tutorial.jar to $jetty.home/lib/ext/jboss (see below for more on this).
- finally, edit the $jetty.home/webapps/standalone/EmbeddedEJB3.jsp file. The JNDI lookups for the beans in this file don’t work and don’t match the documentation, so you need to change them. Find the lines:
CustomerDAOLocal local = (CustomerDAOLocal) ctx.lookup(CustomerDAOLocal.class.getName()); CustomerDAORemote remote = (CustomerDAORemote) ctx.lookup(CustomerDAORemote.class.getName());
change them to:
CustomerDAOLocal local = (CustomerDAOLocal) ctx.lookup("CustomerDAOBean/local"); CustomerDAORemote remote = (CustomerDAORemote) ctx.lookup("CustomerDAOBean/remote");
- start jetty: java -jar start.jar and now you can test EJB3s in jetty by surfing to the demo: http://localhost:8080/standalone/EmbeddedEJB3.jsp
I don’t think it should be necessary to move the jboss jars out of the webapp, but it makes sense if you want to use EJB3 with more than one webapp.
I haven’t as yet been able to make it work with leaving the jars inside the webapp. I get a ClassNotFoundException:
Caused by: org.jboss.util.NestedRuntimeException: Cannot load class org.jboss.mx.server.JBossMXServerConfig; - nested throwable: (java.lang.ClassNotFoundException: org.jboss.mx.server.JBossMXServerConfig) at org.jboss.util.Classes.instantiate(Classes.java:514) at org.jboss.mx.server.ServerConfig.getInstance(ServerConfig.java:74) at javax.management.MBeanServerFactory.(MBeanServerFactory.java:79)
The class doesn’t seem to exist in any of the jars supplied with the demo, so the ClassNotFoundException seems reasonable enough. However, I haven’t had time to investigate why it does not occur when the jars are in Jetty’s lib directory.