• Post Reply Bookmark Topic Watch Topic
  • New Topic

First steps in EJB

 
Radoslaw Sztando
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm reading Head First EJB and I'm trying to see how first example works. I'm using standard j2ee 1.3 server.
I managed to create my first session bean and even succesfully deploy it.
Now I want to write a simple client application which will connect to J2EE server and run business method of my bean.
I copied application from the book but it does not work. As far as I know there is sth wrong with JNDI configuration.

My client App code looks like:
<code>
try{
Context ic = new InitialContext();
System.out.println("Looking for component " + name);
Object o = ic.lookup(name);
DoradcaHome ibaz = (DoradcaHome)PortableRemoteObject.narrow(o, DoradcaHome.class);
Doradca doradca = ibaz.create();
System.out.println(doradca.getAdvice());
}catch(Exception e) {
e.printStackTrace();
}
</code>
and it throws exception from ic.lookup(name).
As you can see I haven't configured InitialContext in any way - I just don't know how to do it.

Can anyone help?

Thanks in advance
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the ways the book fails I'm afraid. It doesn't work like that (at least with SJSAS, maybe it worked with the 1.3 RI server).
You'll need to create a client application archive using the deploytool (no need to put it in the ear) and run that instead.

Create a new application client containing the client classfile and classfiles for the EJB interfaces, give it an EJB ref to the EJB, and save it to your harddisk.
After that, use the "appclient" tool from SJSAS to run the client.

This assumes you're on the same machine as the appserver obviously, as mentioned on page 58 ways to get the client to run remotely are explained later.
 
Radoslaw Sztando
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

I will try this out as soon as possible

Regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!