Creating EJBs with XDoclet

I’ve been meaning to have a look at XDoclet for a while now, and finally got round to figuring out how to use it when developing EJBs today. XDoclet 1.2.3 is the most recent stable version. However, the component of XDoclet that parses source code – XJavaDoc – doesn’t support Java 5 code (that uses parameterised types or annotations, for example). Fortunately, there is a newer version of XJavaDoc that can be used – just replace xjavadoc-1.1.jar in the XDoclet download with xjavadoc-1.5-snapshot050611.jar and it seems to work.

The files that XDoclet generates are controlled by the subtasks that go inside the <ejbdoclet> task in your Ant build file. Our EJBs are deployed to JBoss; XDoclet can be used to generate most of the files we need:

  • remote interface – <remoteinterface> subtask
  • home interface – <homeinterface> subtask
  • ejb-jar.xml<deploymentdescriptor> subtask
  • jboss.xml<jboss> subtask.

If you’re writing your EJB by extending Spring’s AbstractStatelessSessionBean class, there are a couple of other things you’ll need to watch out for.

Firstly, you’ll need the Spring JAR (or JARs) on the Ant task classpath (not the Eclipse project’s classpath) – or XDoclet won’t create any files, and won’t give you any indication why (a NoClassDefFoundError would be nice!).

Secondly, you’ll need to add this to the Javadoc for your EJB implementation class:

@ejb.interface extends="javax.ejb.EJBObject"
@ejb.home extends="javax.ejb.EJBHome"

Otherwise, the generated remote and home interfaces will extend interfaces that don’t exist!

This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s