aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Help,Tomcat can't invoke EJB? 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 "Help,Tomcat can Watch "Help,Tomcat can New topic
Author

Help,Tomcat can't invoke EJB?

Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
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:


When I face C# and Java I choose Java.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
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?


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
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:
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


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

Joined: Jul 18, 2001
Posts: 2712
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

Joined: Feb 17, 2003
Posts: 152
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

Joined: Feb 17, 2003
Posts: 152
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

Joined: Jul 18, 2001
Posts: 2712
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help,Tomcat can't invoke EJB?