2 Replies Latest reply on Oct 6, 2005 12:43 PM by Kalyan

    EJB Client Classpath

    Kalyan Newbie

      Hi All,

      Does the dynamic class downloading feature of RMI download any class that's not available in the client's class path?

      Let's say I have the following code on the client:

      Object o = context.lookup("jndiName");
      ExampleHome h = (ExampleHome)PortableRemoteObject.narrow(o,ExampleHome.class);
      
      


      Now, is it mandatory that I have the ExampleHome's class file in the
      classpath for this client program to run? Or does it get dynamically
      downloaded from the server (since it's contained in the jar file of the deployed bean).

      If this class has to be present in the client's classpath, then what exactly
      does the dynamic class downloading do?

      Thanks,
      Kalyan.

        • 1. Re: EJB Client Classpath
          Clive Jordan Newbie

          Hi Kaylan,

          My understanding is that the client must have copies of the home and component interfaces. You do not need the bean class (and would not provide that as it contains your business logic).

          Cheers,
          Clive

          • 2. Re: EJB Client Classpath
            Kalyan Newbie

            Thanks. I'm aware of the fact that bean class is not needed on the client side. One doesn't have to always have the remote and home interface classes on the client side. For example, the following code works pretty well without those interfaces on the client side (since there is no direct reference for the interface in the code):

            Object obj = context.lookup("server.Server");
             Method m = obj.getClass().getDeclaredMethod("create",null);
             Object remote = m.invoke(obj,null);
             Method rm = remote.getClass().getDeclaredMethod("getInformation",null);
             Object result = rm.invoke(remote,new Object[]{queueName});
             System.out.println("Information the other way: "+result);

            In this case the proxy's instance representing the ServerHome (and I believe it implements this interface as well) gets downloaded to the client and along with its codebase annotation pointing to the codebase of the Jboss server. Once it gets that, since it doesn't have the ServerHome interface's class definition, it downloads the definition from the server. Someone from JBoss or who knows the internals of it, please correct me if I'm wrong in my interpretation. I also believe that the RMIClassLoader is used to download the class definition from the codebase. When it was able to download the definition for a proxy, why was it not able to download it when I type cast the interface? (I have also tried setting the RMIClassLoader as the context class loader, with the appropriate code base, but still I get the NoClassDefFoundError.

            Thread.currentThread().setContextClassLoader(RMIClassLoader.getClassLoader("http://mymachine:8083/"));


            I hope this makes my question clear now.

            Thanks,
            Kalyan.