2 Replies Latest reply on Sep 7, 2003 9:20 PM by wmprice

    Error while calling EJB from Servlet

    srshende

      Hi All,
      I am getting an error while calling EJB from servlet. I have put all the ejb class files in the CLASSPATH and successfully deployed the same on server too. But when I am compling Servlet it gives compile time error as below :

      access javax.ejb.EJBHome
      file javax\ejb\EJBHome.class

      cannot access javax.ejb.EJBHome
      file javax\ejb\EJBObject.class not found

      I have given the classPath of my home and remote claasses properlly.

      Could you let me know the exact reason for the same.
      I am using jboss-4.0.0DR1_tomcat-4.1.24
      Here is code for accessing eJb:
      ----------------------------------------------------------------
      InitialContext ctx = new InitialContext();
      Object ref = ctx.lookup("Activity/activity");
      ActivityHome activityHome = (ActivityHome)PortableRemoteObject.narrow(ref, ActivityHome.class);
      activity = (Activity)activityHome.create();



      ~Sanjay

        • 1. Re: Error while calling EJB from Servlet



          private ActivityHome getHome() throws NamingException {

          Object result = getContext().lookup(ActivityHome.JNDI_NAME);
          return ( (ActivityHome) PortableRemoteObject.narrow(result,ActivityHome.class));

          }

          Note :: JNDI_NAME will be something ActivityHomeBean

          private InitialContext getContext() throws NamingException {

          Hashtable props = new Hashtable();
          props.put(
          InitialContext.INITIAL_CONTEXT_FACTORY,
          "org.jnp.interfaces.NamingContextFactory");
          props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");

          InitialContext initialContext = new InitialContext(props);
          return initialContext;
          }


          Try this way, its just that i have made it in diffrent methods. You can put debug staements in bot themethods and can see where it is failing. I can ser that yr JNDI_NAME is wrong like "Activity/activity".

          Also you are typecating yr ActivityHome in craete call.
          Thers is no need for that because home interface's create call returns the reference to remote object interface in this case it is called Activity.

          So just do
          Activity myBean = getHome().create();
          I hope all this helps you with.

          Cheers.......
          Vishal

          • 2. Re: Error while calling EJB from Servlet

            The problem is not looking up a reference to the ejb, the problem is in compiling your Servlet. The compiler is telling you that it cannot find the appropriate javax.ejb.* classes and thus it is failing. You need to reference jbossall-client.jar on your compilation classpath. You can find this jar in your $JBOSS_HOME/client/ directory.

            Regards,

            Weston