• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Help,Tomcat can't invoke EJB?

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone:

I write a simple EJB(SessionBean) and it have Remote interface(Hello),Home interface(HelloHome) and bean class(HelloBean).I deploy it in sun's deploytool successfully(return a HelloClient.jar).I try to invoke The "Hello" EJB in the same computer using Tomcat.My code is:
///////////////////////invokeEJB.jsp////////////////////////////////
<%@page import="javax.ejb.*,javax.naming.*"%>
........... ......... ................. ............
try{
Context ctx=new InitialContext();
Object obj=ctx.lookup("java:comp/env/ejb/Hello");
HelloHome home=(HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
Hello hello=home.create();
out.println(hello.getHello());
}catch(Exception e){
out.println(e.toString());
}
........... .......... ............ ......................
But Tomcat report error:
////////////////////////////////////////////////////
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.

An error occured between lines: 7 and 17 in the jsp file: /ejb/invokeejb.jsp
Generated servlet error:
g:\j2sdkee1.3\repository\lyo\web\ejb\_0002fejb_0002finvokeejb_jsp.java:64: Class org.apache.jsp.HelloHome not found.
HelloHome home=(HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
^

An error occured between lines: 7 and 17 in the jsp file: /ejb/invokeejb.jsp
Generated servlet error:
g:\j2sdkee1.3\repository\lyo\web\ejb\_0002fejb_0002finvokeejb_jsp.java:64: Class org.apache.jsp.HelloHome not found.
HelloHome home=(HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
^

An error occured between lines: 7 and 17 in the jsp file: /ejb/invokeejb.jsp
Generated servlet error:
g:\j2sdkee1.3\repository\lyo\web\ejb\_0002fejb_0002finvokeejb_jsp.java:64: Undefined variable or class name: PortableRemoteObject
HelloHome home=(HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
^

An error occured between lines: 7 and 17 in the jsp file: /ejb/invokeejb.jsp
Generated servlet error:
g:\j2sdkee1.3\repository\lyo\web\ejb\_0002fejb_0002finvokeejb_jsp.java:65: Class org.apache.jsp.Hello not found.
Hello hello=home.create();
^
4 errors, 1 warning
Why? :roll:
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to invoke The "Hello" EJB in the same computer using Tomcat.
hmm.. Tomcat is a web container, not an EJB container. Am I missing something here?
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you:
But I want to invoke the EJB only in the Tomcat other than run the EJB in Tomcat.The EJB run in the sun's J2EE server(E:\j2sdkee1.3\...).The j2EE and the Tomcat were in the same computer.
Whether I missing some jar files in Tomcat?(for example: stub file,ejb-client.jar)But I add the ejb-client.jar to Tomcat it also can't work?!Why? :roll:
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are HelloHome, Hello and HelloBean defined in the default package (assuming from the missing import)? Try to move them into a package. Some appservers have trouble with components belonging to the default package.
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:
Some appservers have trouble with components belonging to the default package.


This is definitely the case with JSP pages. it is a failing of the JSP Specification. The spec does not explicitly define whether classes in the default package should be made available to JSP pages, therefore some Web Containers make them available and some do not.
Moral of the story: Never leave your classes in the default package.
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone:
I try to write a javabean and I use it in jsp page "<jsp:useBean.... ../>".It can be compiled successfully if I don't package the javabean.But it can't compile if I package it.My javabean code is:
//////////////////////////testejb.java///////////////////////////////////
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
public class testejb{
String hi=null;
public testejb(){
try{
Context ctx=new InitialContext();
Object obj=ctx.lookup("ejb/Hello");
Hellohome home=(Hellohome)PortableRemoteObject.narrow(obj,Hellohome.class);
Hello hello=home.create();
hi=hello.getHello();
}catch(Exception e){
System.out.println(e.toString());
}
}
public String callejb(){
return this.hi;
}
public static void main(String args[]){
testejb li=new testejb();
li.callejb();
}
///////////////////////////////////////////////////////////////////////
I means that it can't compile if I add "package testejb" at the front.But if I don't add "package testejb" it compile successfully.Why?I have add the HelloClient.jar(return by sun's deploytool) to my classpath.Any problem? :roll:
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:
Are HelloHome, Hello and HelloBean defined in the default package (assuming from the missing import)? Try to move them into a package. Some appservers have trouble with components belonging to the default package.


The "HelloHome, Hello and HelloBean" are in the same jar file(HelloClient.jar) and I add it in my classpath.It is created by deploytool.I use sun's deploytool.But the Tomcat report error if I import the jar using " import="HelloClient.Hellohome,HelloClient.Hello" ".
Can't I invoke the EJB in Tomcat if I don't integrate JBoss? :roll:
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yashnoo lyo:
[QB]The "HelloHome, Hello and HelloBean" are in the same jar file(HelloClient.jar) and I add it in my classpath.


What jar classes are in has nothing to do with which package they are in... my recommendation is to make sure your ejb classes are not in the default package. In other words you will need to explicitly define which package they are in using the package keyword.
On another note, your ejb lookup is only going to work if you are retrieving the InitialContext correctly. Check the documentation for your Server on how to do this.
[ August 17, 2003: Message edited by: Chris Mathews ]
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic