java ee - EJB Lookup Issue with WebSphere Application Server 6.1 -
at first want tell similar type of questions has been asked here still can't find solution of problem.
i have ejb 3 project (name = helloworldejbproject). there have created stateless remote ejb (name = helloworldejb). have created remote interface there (name= helloworldejbinterfaceremote). after creating jar & ear of project after compiling using ant. deployed ear in websphere application server 6.1.
next have created stand alone java project (name = helloworldclient), put jar of helloworldejbproject project build path. while doing getting errors.
helloworldejb.java:
package com.staples.ejb; import com.staples.ejb.interfaces.helloworldejbinterfaceremote; import javax.ejb.stateless; @stateless public class helloworldejb implements helloworldejbinterfaceremote { public helloworldejb() { } public string helloworld() { return "hello world"; } }
client.java (inside helloworldclient project):
package com.staples.client.processor; import com.staples.client.util.applicationutil; import com.staples.ejb.interfaces.helloworldejbinterfaceremote; public class client { static private helloworldejbinterfaceremote hellointerface = applicationutil.gethelloejbhandle(); public static void main(string[] args) { system.out.println(hellointerface.helloworld()); } }
applicationutil.java (inside helloworldclient project):
import java.util.hashtable; import javax.naming.context; import javax.naming.initialcontext; import javax.naming.namingexception; import javax.rmi.portableremoteobject; import com.staples.ejb.interfaces.helloworldejbinterfaceremote; public class applicationutil { public static object getcontext(){ object obj = null; context context; try { hashtable env = new hashtable(); env.put(context.initial_context_factory,"com.ibm.websphere.naming.wsninitialcontextfactory"); env.put(context.provider_url,"corbaloc:iiop:localhost:2811"); context ctx = new initialcontext(env); obj = ctx.lookup("ejb/helloear/hello.jar/helloworldejb#" + helloworldejbinterfaceremote.class.getname()); } catch (namingexception e) { e.printstacktrace(); } return obj; } public static helloworldejbinterfaceremote gethelloejbhandle() { object obj = getcontext(); helloworldejbinterfaceremote hellointerface = (helloworldejbinterfaceremote) portableremoteobject.narrow(obj, helloworldejbinterfaceremote.class); //helloworldejbinterfaceremote hellointerface = (helloworldejbinterfaceremote) obj; return hellointerface; }
error:
exception in thread "p=141210:o=0:ct" java.lang.classcastexception: unable load class: com.staples.ejb.interfaces._helloworldejbinterfaceremote_stub @ com.ibm.rmi.javax.rmi.portableremoteobject.narrow(portableremoteobject.java:372) @ javax.rmi.portableremoteobject.narrow(portableremoteobject.java:156) @ com.staples.client.util.applicationutil.gethelloejbhandle(applicationutil.java:41) @ com.staples.client.processor.client.main(client.java:14)
if comment following
helloworldejbinterfaceremote hellointerface = (helloworldejbinterfaceremote) portableremoteobject.narrow(obj, helloworldejbinterfaceremote.class);
& uncomment following:
helloworldejbinterfaceremote hellointerface = (helloworldejbinterfaceremote) obj;
then following error comes:
exception in thread "p=346416:o=0:ct" java.lang.classcastexception: org.omg.stub.java.rmi._remote_stub incompatible com.staples.ejb.interfaces.helloworldejbinterfaceremote @ com.staples.client.util.applicationutil.gethelloejbhandle(applicationutil.java:42) @ com.staples.client.processor.client.main(client.java:14)
i using ejb 3 guess dont need portableremoteobject.narrow without using different error. not sure write argument of context.lookup(). pretty new in ejb. can me please? in advance. magicwand & bkail solve port & jndi problems.
after have started getting namingexception
, using com.staples.ejb.interfaces.helloworldejbinterfaceremote
jndi
lookup string should work. have tried using too?
Comments
Post a Comment