aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Calling EJB from standalone java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Calling EJB from standalone java program" Watch "Calling EJB from standalone java program" New topic
Author

Calling EJB from standalone java program

Manoj Gundawar
Ranch Hand

Joined: Nov 17, 2002
Posts: 169
Hi,

I have developed EJB in WSAD. I can call it from standalone java, only if this java project is developed under WSAD and run under same JRE. But I need to find out how to run it in different jre's (using Sun's java instead of IBM's)
I could not find much help on this one. Any suggestions? (or related links would do)
Thanks,
Manoj


Manoj<br />SCJP, SCJD, SCWCD, IBM WSAD.
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
I might be saying sutff that you already know, but... just ignore it if so.

If you can access your ejb from a java program under wsad it means that both your java client and you ejb (and server) configuration are fine.
The only reason i see for that not working on projects outside wsad (in fact, in other jvm) is that might be looking for local interfaces. You can access local interfaces only from the same jvm.


Leandro Melo
SCJP 1.4, SCWCD 1.4
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
I have never been able to get a client program to access WebSphere without using the JVM shipped with WebSphere. I too, would be interested in learning how to do that with Sun's JVM.
Manoj Gundawar
Ranch Hand

Joined: Nov 17, 2002
Posts: 169
Hi Leandro,
Thanks for reply.
But I didnt get what you ment by "You can access local interfaces only from the same jvm" I have put the ejb jar in the classpath of the standalone client , so that client gets all the required classes. (this jar has local interface,home interface, stub and skeleton classes)

As this was not happening (call to ejb), I created a Servlet which does exactly same process as EJB and now I call this servlet from the Standalone Java Client. But the performance is not good. I am not sure if I use the
EJB instead, performance will improve. Any idea?

Thanks,
Manoj
SivaKumar Kumar
Greenhorn

Joined: Sep 04, 2004
Posts: 6
An EJB can be built with a local / remote interface

The local interface is used when you access the EJB from within the same JVM as your Application server. ie your servlet accessing the EJB. This is done for performance improvement.

The remote interface is used when you access the EJB from another JVM. ie your client accessing the EJB.

I have not used IBM's JVM but I wouldn't think there will be any difference in accessing a SUN JVM.
SivaKumar Kumar
Greenhorn

Joined: Sep 04, 2004
Posts: 6
Even though you have put the ejb jar in the classpath it will still be a remote call to the EJB on the JVM running the Application server.

The "EJB jar" file contains the stubs you need to connect to the Application server that has the EJB's.

You may also want to check that you are able to connect to the JVM containing the EJB's. ie your JNDI entries are correct.

you need at least the following JNDI entries (this is for Weblogic)
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.provider.url=t3://<host>:<port>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Calling EJB from standalone java program