Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: error in Naming.bind of basis server application

  1. #1
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default error in Naming.bind of basis server application

    What is going wrong here concerning the "bindings"
    Learning server stuff and testing some basic applications from the Corejava II book.
    Here is the error code when "Naming.bind" two strings called toaster and microwave:
    ProductImpl p1 = new ProductImpl("Blackwell Toaster");
    Naming.bind("toaster", p1);
    (see the productserver class of the liste code):

    Constructing server implementations...
    Binding server implementations to registry...
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    Error: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: serverstuff.Product
    java.lang.ClassNotFoundException: serverstuff.Product
    at sun.rmi.server.UnicastServerRef.oldDispatch(Unicas tServerRef.java:400)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:248)
    at sun.rmi.transport.Transport$1.run(Transport.java:1 59)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport. java:155)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:535)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(TCPTransport.java:790)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:649)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:680)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceiv edFromServer(StreamRemoteCall.java:255)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Str eamRemoteCall.java:233)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:3 59)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at java.rmi.Naming.rebind(Naming.java:160)
    at serverstuff.ProductServer.main(ProductServer.java: 40)
    Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: serverstuff.Product
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknow n Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(Unicas tServerRef.java:390)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:248)
    at sun.rmi.transport.Transport$1.run(Transport.java:1 59)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport. java:155)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:535)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(TCPTransport.java:790)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:649)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:680)
    Caused by: java.lang.ClassNotFoundException: serverstuff.Product
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:249)
    at sun.rmi.server.LoaderHandler.loadProxyInterfaces(L oaderHandler.java:709)
    at sun.rmi.server.LoaderHandler.loadProxyClass(Loader Handler.java:653)
    at sun.rmi.server.LoaderHandler.loadProxyClass(Loader Handler.java:590)
    at java.rmi.server.RMIClassLoader$2.loadProxyClass(RM IClassLoader.java:628)
    at java.rmi.server.RMIClassLoader.loadProxyClass(RMIC lassLoader.java:294)
    at sun.rmi.server.MarshalInputStream.resolveProxyClas s(MarshalInputStream.java:242)
    at java.io.ObjectInputStream.readProxyDesc(ObjectInpu tStream.java:1535)
    at java.io.ObjectInputStream.readClassDesc(ObjectInpu tStream.java:1491)
    at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1748)
    at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1327)
    at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:349)
    ... 12 more


    package serverstuff;
     
    /**
     * The interface for remote product objects.
     * Gets the description of this product.
     * @return the product description
     * 
     */
    import java.rmi.*;
     
    public interface Product extends Remote {
        String getDescription() throws RemoteException;
    }


    package serverstuff;
     
    /**
     * This server program instantiates two remote
     * objects, registers them with the naming service,
     * and waits for clients to invoke methods on the
     * remote objects.
     * 
     */
     
     
    /**
     * @version 1.10 1999-08-21
     * @author Cay Horstmann
     */
     
    import java.rmi.*;
    import java.rmi.server.*;
     
     
    public class ProductServer
    {  public static void main(String args[])
       {  try
          {  System.out.println
                ("Constructing server implementations...");
     
             ProductImpl p1
                = new ProductImpl("Blackwell Toaster");
             ProductImpl p2
                = new ProductImpl("ZapXpress Microwave Oven");
     
             System.out.println
                ("Binding server implementations to registry...");
     
             Naming.rebind("toaster", p1);
             Naming.rebind("microwave", p2);
     
             System.out.println
                ("Waiting for invocations from clients...");
          }
          catch(Exception e)
          {  System.out.println("Error: " + e);
             e.printStackTrace();
          }
       }
    }


    package serverstuff;
     
     
    /**
     * @version 1.00 1996-09-07
     * @author Cay Horstmann
     * This is the implementation class
     * for the remote product
     * Constructs a product implementation
     * @param n the product name
     *
     */
     
    import java.rmi.*;
    import java.rmi.server.*;
     
    public class ProductImpl extends UnicastRemoteObject
                               implements Product {
        public ProductImpl(String n)
           throws RemoteException {
           name = n;
        }
     
       public String getDescription() throws RemoteException {
          return "I am a " + name + ". Buy me!";
       }
     
       private String name;
    }


  2. #2
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: error in Naming.bind of basis server application

    The problem might be the classpath, because the RMI registry has its own classpath.
    So how to set the correct class path for the RMI registry?



    registry - Java RMI InitialContext: Equivalent of LocateRegistry.createRegistry(int)? - Stack Overflow
    After much tinkering, I've solved the problem. FYI, here's what it was:

    The ClassNotFoundException is getting thrown because of RMI registry has its own classpath. It doesn't matter that the class containing the InitialContext has the custom objects on its classpath - The RMI registry must be initialised such that the custom objects are on its classpath as well.

    To do this set the classpath environment value on the comman line prior to starting rmiregistry. If this classpath contains the custom object's class, the ClassNotFoundException is not thrown, and subsequently ServerException and `CommunicationException' are avoided.

    --- Update ---

    Keep getting this error which says: ClassNotFoundException: serverstuff.Product
    While that file is present at the serverstuff!
    The file is actually a interface..... might that be the problem... I don't think so?

    package serverstuff;
     
    /**
     * The interface for remote product objects.
     * Gets the description of this product.
     * @return the product description
     * 
     */
    import java.rmi.*;
     
    public interface Product extends Remote {
        String getDescription() throws RemoteException;
    }

    Binding server implementations to registry...
    Error: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: serverstuff.Product
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: serverstuff.Product

  3. #3
    Member
    Join Date
    Jun 2013
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: error in Naming.bind of basis server application

    You see gimbal until now I have been working, without exception, in the Netbeans environment (very cozy).
    I had no command line experience at all! Working with netbeans you run very little into flags
    classpath etc because Netbeans does it all for you. Until now that was perfect since I concentrated fully onto the java programming language which was already hard enough to learn.
    But from learning DB I was forced to look into doing java from the command line which turned out to be
    a real disaster because I had no idea how to do things. So I looked into Unix.
    You see most programming books do not go a lot into flags classpath etc. they tend to focus on the java grammar only!
    Since I do not have a computer science education I am picking up things in a unconventional way, but I am gone make it (eventually).

    I hop other blog members recognize what I am talking about?

Similar Threads

  1. Replies: 0
    Last Post: July 16th, 2013, 06:12 AM
  2. Replies: 7
    Last Post: December 28th, 2012, 10:48 AM
  3. Java Application Server
    By goutamdaphtari in forum Java Theory & Questions
    Replies: 0
    Last Post: July 14th, 2010, 11:53 PM
  4. Replies: 0
    Last Post: May 21st, 2009, 11:17 AM