• 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
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

can call EJB from Java App But not from Servlet

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have created a helloWorld EJB and deploy it on the Sun Application Server. However I can not get my Servlet to call the business method on the Servlet. So I create a java application just to call the EJB. It really surprise me that the java app can call the helloworld app successfully. I wonder if the there is some servlet deployment problem I encounter? I am using tomcat-5_5_8.

The code that I am using to call the EJB is the same as in the servlet and the java app.

code :

Properties env = new Properties();

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
env.put("java.naming.provider.url", "iiop://127.0.0.1:3780");
env.put("java.naming.security.principal", "user");
env.put("java.naming.security.credentials", "password");

Context con = new InitialContext(env);

Object obj = con.lookup("ejb/HelloWorldBean");

HelloWorldRemoteHome home = (HelloWorldRemoteHome) PortableRemoteObject.narrow(obj, HelloWorldRemoteHome.class);

HelloWorldRemote businObj = home.create();

String msg = businObj.getHelloWorldMsg();
businObj.remove();

//end of code.

the code that has error is this line :
HelloWorldRemoteHome home = (HelloWorldRemoteHome) PortableRemoteObject.narrow(obj, HelloWorldRemoteHome.class);

The error code is noClassDefFound error
: can not find the class com.sample.HelloWorldRemoteHome

However I have include the same client.jar in my java app and servlet.
So I dont think the problem is the client.jar file.

Thanks for the interest in reading my long question.

Thanks
Chee Yong

LPP (Lowest Paid Programmer)

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you really included EJBs client classes to your client's classpath? It says that com.sample.HelloWorldRemoteHome cannot be found in classpath. Simply you could put your EJBs jar to client classpath and test.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure your EJB client jar is in the classpath of your web app.
 
Chee Yong Foo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for the replies to my question. But I am pretty sure I added the client.jar file to my web app. When I open up the war file, I see my EJB client.jar in the WEB-INF/lib/
So does that mean that I have added in the client.jar in my web app classpath successgfully?

Cheers
Chee Yong
 
Saulius Sinkunas
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Open client.jar and look if this file com/sample/HelloWorldRemoteHome.class is there?

Can yuo call your EJB from standalone client, not servlet?
 
Chee Yong Foo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thanks for the help I have received from the people here. I have discover the problem. It is because I include j2ee.jar in my web war file. I deploy my war file on Tomcat server. Tomcat come with its own javax.servlet.* and javax.jsp.* package.
When the class loader trys to load the j2ee.jar, it discover a namespace crash with javax.servlet.* and javax.jsp.* package. Therefore class loader will not load the j2ee.jar and theremore it will not load any of the jar files that come after j2ee.jar eg. myEJBClient.jar.
Thats explains my classNotFoundException. In order to solve this, I use a jar file with only javax.ejb.*.

Thanks for the help!
Cheers
Chee Yong
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good to hear that you've solved the problem. Thanks for including your solutions too which would benefit others.
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic