Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to call a simple EJB (stateless session bean) -outside the conext

Status
Not open for further replies.

patnim17

Programmer
Jun 19, 2005
111
US
Hi,
I have a simple Stateless session bean depployed in my local machine in weblogoc 8.1.

Now I have a test java program with main method in it, that is not deployed in the weblogic server. I need to just call this EJB from this Test Java prgram.

What are the steps I need to call this EJB. I need to know the steps to create the initial context and then do a lookup.

thanks
pat
 
If your context parameters are specified in a jndi.properties file somewhere on the classpath, then creating the initial context is as simple as
Code:
Context ctx = new InitialContext();

Then you'd probably have something like this to get the Home Interface for your bean:-
Code:
      Object obj = initialContext.lookup("jndi lookup");
      Homeinterface home = (Homeinterface)javax.rmi.PortableRemoteObject.narrow(obj, Homeinterface.class);

Tim
 
thanks for the response.
If I don't have the jndi.properties file...then how do I create the initialContext object?
 
I'd recommend using a jndi.properties file because it allows you to redeploy you client without altering code. You can create one easily enough, you know. It's only a text file in the format of property=value pairings, one per line.

If you don't want to do that, you can always put your values into a Hashtable and pass that into the InitialContext constructor. It will create an InitialContext from that.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top