jQuery in Action, 2nd edition*
The moose likes Tomcat and the fly likes Why can't I invoke a ejb in Tomcat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Why can Watch "Why can New topic
Author

Why can't I invoke a ejb in Tomcat?

Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi everyone:
I invoke a ejb in Tomcat(the ejb is in the weblogic in the same computer with tomcat).The jsp code is:
/////////////////first method//////////////////////
Context ctx=new InitialContext();
Object obj=ctx.lookup("ejb/Hello");
Hellohome home=(Hellohome)PortableRemoteObject.narrow(obj,Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());
///////////////second method//////////////////
Hashtable ht=new Hashtable();
Context ctx=null;
ht.put(ctx.PROVIDER_URL, "t3://127.0.0.1:7001" ); // t3://127.0.0.1:7001
ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ctx = new InitialContext();
Hellohome home= (Hellohome) javax.rmi.PortableRemoteObject.narrow (ctx.lookup ("HelloEJB"),Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());
Is there any different?If I want to invoke the EJB which is in the weblogic.The Tomcat says:
//////////////////////////////////////////////
Name HelloEJB is not bound in this Context
But I bound it in the weblogic and I add the "
<ejb-ref>
<ejb-ref-name>HelloEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>lyoejb.Hellohome</home>
<remote>lyoejb.Hello</remote>
<ejb-link>Hello.jar#HelloEJB</ejb-link>
</ejb-ref>"
in the ejb-jar.xml. And I copy the j2ee.jar,wlclient.jar,Hello.jar to Tomcat/....web-inf/lib
How to setting the web.xml in the Tomcat? :roll:


When I face C# and Java I choose Java.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

Moving to Tomcat forum.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You need to use the Hashtable for creating the InitialContext...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Thank you.

But I find that the first code will be work property if I run the jsp in weblogic:
/////////////////first method//////////////////////
Context ctx=new InitialContext();
Object obj=ctx.lookup("ejb/Hello");
Hellohome home=(Hellohome)PortableRemoteObject.narrow(obj,Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());

But if the client is Tomcat the above code can't work.I must use the second code:
///////////////second method//////////////////
Hashtable ht=new Hashtable();
Context ctx=null;
ht.put(ctx.PROVIDER_URL, "t3://127.0.0.1:7001" ); // t3://127.0.0.1:7001
ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ctx = new InitialContext();
Hellohome home= (Hellohome) javax.rmi.PortableRemoteObject.narrow (ctx.lookup ("HelloEJB"),Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());
Does it because the jndi is in the weblogic so it needn't to use hashtable to place weblogic.jndi....in it? :roll:
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Thank you.

But I find that the first code will be work property if I run the jsp in weblogic:
/////////////////first method//////////////////////
Context ctx=new InitialContext();
Object obj=ctx.lookup("ejb/Hello");
Hellohome home=(Hellohome)PortableRemoteObject.narrow(obj,Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());

But if the client is Tomcat the above code can't work.I must use the second code:
///////////////second method//////////////////
Hashtable ht=new Hashtable();
Context ctx=null;
ht.put(ctx.PROVIDER_URL, "t3://127.0.0.1:7001" ); // t3://127.0.0.1:7001
ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ctx = new InitialContext();
Hellohome home= (Hellohome) javax.rmi.PortableRemoteObject.narrow (ctx.lookup ("HelloEJB"),Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());
Does it because the jndi is in the weblogic so it needn't to use hashtable to place weblogic.jndi....in it? :roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why can't I invoke a ejb in Tomcat?
 
Similar Threads
HOW TO ACCESS EJB FORM CLIENT
I have deployed my ejb with Weblogic and I have a problem with my client
Calling a EJB in a different Websphere instance
NameNotfoundexception
Help,Tomcat can't invoke EJB?