Please forgive me if there's an answer to this around here - I looked as best I could.
I'm reading the Head First EJB book and working through the Advice tutorial in the intro to EJB chapter (chapter 1). Instead of using the tools recommended in the book I'm developing in NetBeans 5.0 Beta and deploying on JBoss 4.0.3rc1 (I know, I know...). Anyway, I'm not a total n00b at this, so I have my EJB deployed successfully, but then it tells me that the server will produce a client jar that my client app can use.
Well, I looked all over creation and can't find a client jar that JBoss produces nor a way to generate one from either JBoss or NetBeans. From an enterprise project NB5 has drop down menu options to call an EJB, but from a POJO I'm not sure how to do it. I know I should just be doing the tutorial the way I'm supposed to be doing it, but I was hoping to work through the same exercises in an environment I'm more comfortable in. Sometimes I think you learn more if you have to puzzle your way through unfamiliar territory.
Anyway, does anyone know how I can get this client jar using my environment or if NB5 has a way to use an EJB from a POJO?
An EJB client JAR is a JAR containing containing the home and remote interfaces only.
The client JAR file must also include the implementations of the interfaces. Furthermore, classes are needed for parameter and return types (think, for instance, about the need to deserialize a return object which rerquires that object's class file).
You will have to create one yourself.
I'm not familiar with JBOSS, but what is typical is that the EJB Server vendor provides an Ant task which generates the client JAR file.
The client JAR file must also include the implementations of the interfaces.
I doubt it. The home and the remote interfaces are required by the client app and not their implementations. Besides, the only other classes required are the primary key class (when applicable) and other custom classes referenced.
All clients use the server bean's home interface to obtain references to the server bean. This reference has the server bean's remote interface datatype, therefore the client interacts with the server bean solely through the methods defined in the remote interface.
I would like to know if I have missed something out.
Perhaps this may help. Perhaps it's not relevant. Generally you do create your own ejb client jar file and this must have the interfaces as described by Annie.
You will need to talk to the JNDI server running on Jboss in order to lookup your home interface. jboss does provide 'client jars' that contain the implementation of client-end of the JNDI stuff you may need. I pulled this snippet from an ant build script that compiles a stand-alone client on the same machine (although in a different JVM). You don't have to use these I'm sure, but they are there if you want them.
If you poke around on jboss, there is a 'client' directory where they store all these jar files. You could use them in your client jar to get access to the JNDI server.
Thanks for the answers. When I get home tonight I'll try out your suggestions and report back my success (hopefully) here. It seems rather odd that the otherwise very thorough book wouldn't cover creating the client jar in detail.
I'm in a similar conundrum. I currently develop in a WebLogic environment, and our build scripts use the ejbgen ant task to create (at least part of) the client JAR file. That task takes care of bundling up all of the Local and Remote interfaces, as well as making a stab at bundling in all of the return types used (DTO's, etc.).
Has anyone found an equivalent tool that will do that packaging, that does not use ejbgen?
You should be able to grab xdoclet (I think it is on sourceforge). I believe xdoclet is what is underneath the covers of ejbgen in weblogic although I am not sure how the syntax differs though.
The idea is fairly similar in that you add special documentation tags to your bean class and then process it to produce all the interfaces etc. You can also integrate it with ant so you can have one build script that should be able to generate jboss or weblogic support files depending on the target you call.
Can be fiddly to settup but I believe the effort is worth it in the long run.