• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please provide a some code for looking up EJB from a simple class

 
Caesar Dutta
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Date: 18 September, 2004

Hi all,

I am very new to EJB and JNDI. I know only how to write simple stateful
and stateless session bean using Sun Java System Application Server.

I have written a very simple stateful bean which has only one business
method getMyName() and returns "Caesar".

The name of EJB in ejb-jar.xml is "SimpleStatefulEJB" and the jndi name
in sun-ejb-jar.xml is "TheSSEJB".

All I now want is this. I will have a simple JAVA class which can call this EJB.

Can anybody provide me some few line of code with instructions.

Your help will be highly appreciated.

Thanks in advance -

Caesar
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34863
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caesar,
Welcome to Javaranch!

Sun's online book walks you through the syntax of the application client.
 
Caesar Dutta
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne. I did went through the tutorial. My problem is
this line -
Context myEnv = Context)initial.lookup("java:comp/env");

What is ths "java:comp/env" ??? I can understand the latter part ejb/jndiname because I know that I am setting that in sun-ejb-jar.xml with
reference to my bean.

I have solved my problem actually by using this:
InitialContext ic = new InitialContext();
Object homeObj = ic.lookup("corbaname:iiop:1.2@localhost:3700#TheSayMyName");

Well only thing I understand is 3700 the RMI-IIOP port and the JNDI name
of my bean "TheSayMyName" as appears in sun-ejb-jar.xml.

But what about the rest? If I would have not found the piece of code from
internet then how to know that string?

I am coming across lot of example in the internet where they are first
creating a Initial naming context and putting some values (url type) in
properties and then suing that properties class to create initial context.

I just cannot understand those strings?

Please help.

Thanks again,

Caesar
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34863
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caesar,
"java:comp/env" is an environmental context. The initial context can contain other contexts (think of them as buckets.) The application server puts all your EJBs in one bucket.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic