Hello,
can someone tell me how to call EJB from a java client application?
Thanks
-
call ejb from java client application (6 messages)
- Posted by: yang yang
- Posted on: September 24 2001 21:41 EDT
Threaded Messages (6)
- call ejb from java client application by Mark Wilcox on September 24 2001 21:57 EDT
- call ejb from java client application by yang yang on September 26 2001 01:12 EDT
-
call ejb from java client application by Venkat Subramani on September 27 2001 10:27 EDT
-
call ejb from java client application by Didik Eko Widarso on March 29 2005 06:04 EST
- Re: call ejb from java client application by Amresh Singh on April 19 2007 05:46 EDT
-
call ejb from java client application by Didik Eko Widarso on March 29 2005 06:04 EST
-
call ejb from java client application by Venkat Subramani on September 27 2001 10:27 EDT
- call ejb from java client application by yang yang on September 26 2001 01:12 EDT
- Re: call ejb from java client application by bhawana sabharwal on April 17 2009 05:57 EDT
-
call ejb from java client application[ Go to top ]
- Posted by: Mark Wilcox
- Posted on: September 24 2001 21:57 EDT
- in response to yang yang
I know to many people this sounds simple, but frankly the examples out there suck.
Luckily it's fairly simple.
First you must put the Home and Remote implementations as well as any utility classes in their own jar. The EJB 2.0 spec allows for automatic creations (WebLogic 6.1's ejbc tool does this for you) by specifying the ejb-client-jar tag like this:
<ejb-client-jar>client.jar</ejb-client-jar> in the ejb.xml file.
Next put this jar file in your client applications classpath.
Import all of the required classes into your application (J2EE stuff as well as your client side stuff):
Then to actually retrieve it:
Context ctx = new InitialContext();
// name is whatever JNDI name you gave it
Object o = ctx.lookup("home name");
EJBHome ejbHome = (EJBHome) PortableRemoteObject.narrow(o,EJBHome.class);
// This is userID should be the one passed.
EJB ejb = ejbHome.create(..);
Mark -
call ejb from java client application[ Go to top ]
- Posted by: yang yang
- Posted on: September 26 2001 01:12 EDT
- in response to Mark Wilcox
Thank you very much.and...
[Next put this jar file in your client applications classpath] means not only deploy this jar in web application server but also copy this jar file to my client machine,doesn't it?
and would you like to show me the whole sample about it?
thanks.
-
call ejb from java client application[ Go to top ]
- Posted by: Venkat Subramani
- Posted on: September 27 2001 22:27 EDT
- in response to yang yang
Yes , even the client program would need the jar.
Some containers like PowerTier also provides a
client application jar which is much thinner and
just carries all the required home and transportation
classes.
You need to set your context factory as well as provider
as follows and pass it to initial context.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://localhost:7001");
InitialContext ic = new InitialContext(env);System.out.println("Got Initial context");
EjbTestHome testhome = (EjbTestHome) PortableRemoteObject.narrow(ic.lookup("MyPackage.MyServerName"), EjbTestHome.class);
-
call ejb from java client application[ Go to top ]
- Posted by: Didik Eko Widarso
- Posted on: March 29 2005 06:04 EST
- in response to Venkat Subramani
I also had a trouble when try to compile stand alone client application to access EJB, i already added the jars on the classpath j2ee.jar, HelloWorldJAR.jar(EJB Jar) and HelloWorldEARClient.jar(Stuff return when i deployed the EBJ). And i allways got like this :
HelloWorldClient.java:32: '.' expected
import HelloWorld;
^
HelloWorldClient.java:33: '.' expected
import HelloWorldHome;
^
2 errors
anybody can tell me what i have to do .....
Thanks -
Re: call ejb from java client application[ Go to top ]
- Posted by: Amresh Singh
- Posted on: April 19 2007 05:46 EDT
- in response to Didik Eko Widarso
This is happening because probably your class HelloWorld is in some package(not in an unnamed package). To verify this, extract your client jar and see whether stub/ EJBObject classes generate for HelloWorld component interface are in some package. Then modify your import statement. it should work. Thanks Amresh -
Re: call ejb from java client application[ Go to top ]
- Posted by: bhawana sabharwal
- Posted on: April 17 2009 05:57 EDT
- in response to yang yang
Hi, can somebody tell me, i am invoking the remote object from the java application & it gives me error: "java.lang.ClassCastException: Could not load a proxy stub. Possible reason is that the context classloader do not has reference to p4 service." at com.sap.engine.services.rmi_p4.P4ObjectBroker.narrow(P4ObjectBroker.java:607) at com.sap.engine.services.rmi_p4.P4ObjectBroker.narrow(P4ObjectBroker.java:453) at com.sap.engine.services.rmi_p4.P4ObjectBroker.narrow(P4ObjectBroker.java:449) at com.sap.engine.services.rmi_p4.reflect.P4InvocationHandler.invokeInternal(P4InvocationHandler.java:171) at com.sap.engine.services.rmi_p4.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:50) at $Proxy0.create(Unknown Source) but if i package & the same java class in the same package with ejb . it works fine. i have checked the ejb is in the class path of my java application thanks