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:

  1. 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).
  2. unjar the war file in docs/embedded-tutorial/embedded-war/build/standalone.war to your $jetty.home/webapps directory.
  3. 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).
  4. 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");
    


  5. 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.


3 Comments

Hani Suleiman · 04/12/2006 at 15:17

So much simpler to use Spring’s pitchfork instead. That way you’re not tied to any provider, and can easily switch from one vendor to another for the JPA implementation. No classpath issues either.

Jan Bartel · 04/12/2006 at 19:37

Hani,

As you’re the second person in a week to mention pitchfork to me, I’ll have to take the hint and check it out 🙂

Note that we’ve done some work so that Jetty will also work with Easybeans (http://www.easybeans.org) – support for Jetty is in Easybeans svn trunk at the moment but is scheduled for the next milestone release. I’ll blog about it a little later.

cheers
Jan

Grant · 06/04/2007 at 00:01

How would one go about incorporating these jars when executing jetty from the maven plugin ? I tried monkeying about with setting the jetty.class.path system property in the pom with <systemProperty>, to no avail. I still get the infuriating
java.lang.ClassNotFoundException: org.jboss.mx.server.JBossMXServerConfig
Any pointers would be greatly appreciated!
Thanks!

Comments are closed.