1 Reply Latest reply on Dec 23, 2002 8:14 AM by Adrian Brock

    RMI vs Local Class Loading

    Dave Newbie

      I don't know if the subject of this message is right ... but i think that's the general problem i'm having ... I have an RMI server (MBean) that has a method exposed that takes a plain Object. This Object is then serialized out to storage so that it can be retrieved later ... The problem I'm having is that when I try to deserialize the object, I get a ClassNotFoundException ... My suspicion is that the RMI framework is using a different ClassLoader than the application code for my RMI server ... Is there anything I can do about this? (aside from putting the classes in the classpath on the RMI server ahead of time?)

      I'm using JBOSS 3.0.4 on JDK 1.3

      Here's my sample code (i've stripped it down so that the call serializes the object into a byte[] array, then tries to deserialize it immeidately ... this demonstrate that even within the RMI call itself, i am unable to instantiate the object); the "setObject()" method is the exposed RMI method ..

      public void setObject(String sessionID, String key, Object value)
      throws Exception{

      java.io.ByteArrayOutputStream bytesOut = new java.io.ByteArrayOutputStream();
      java.io.ObjectOutputStream objectOut = new java.io.ObjectOutputStream(bytesOut);

      byte[] buf = bytesOut.toByteArray();

      java.io.ByteArrayInputStream bytesIn = new java.io.ByteArrayInputStream(buf);
      java.io.ObjectInputStream objIn = new java.io.ObjectInputStream(bytesIn);
      Object obj = objIn.readObject(); //Exception raised here


      The exception is raised on the readObject() call ...

      java.lang.ClassNotFoundException: No ClassLoaders found for: xxxxxxx.servlets.DaveObject
      at org.jboss.mx.loading.LoadMgr.beginLoadTask(LoadMgr.java:138)
      at org.jboss.mx.loading.UnifiedClassLoader3.loadClass(UnifiedClassLoader3.java:140)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:195)
      at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:654)
      at java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:918)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:366)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
      at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1186)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
      at xxxxxx.setObject(SessionManagerImpl.java:270)

      Thanks in advance,

        • 1. Re: RMI vs Local Class Loading
          Adrian Brock Master

          RMI uses the classloader that loaded the stub.

          If you serialize something in a webapp, you
          won't be able to deserialize outside the webapp
          if the classes only exist in the webapp.

          Webapps have their own classloaders that nobody
          else can see.

          I'm guessing, from the phrase "servlets" in the class name.