• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

First steps in EJB

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!

I will try this out as soon as possible

Regards
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic