1

Trying to test the rmi tutorial via Netbeans to set up a remote server - client interface. When running the server the following exception appears:

exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: remotetests.MyRemoteInterface

The rmi registry is running in the background.

It seems the server is unable to publish the remote object?? Below are server, remote interface and client classes

Please help - Thanks!

The server class looks like this:

package remotetests;

import java.io.Serializable;

import java.net.InetAddress;

import java.rmi.*;

import java.rmi.registry.LocateRegistry;

import java.rmi.server.*;


public class MyRemoteClass extends UnicastRemoteObject implements MyRemoteInterface, serializable {

    public MyRemoteClass() throws RemoteException {

        //Constructor code

        System.out.println("MyRemote constructor");

    }

    public void myMethod1() throws RemoteException {

        //Here we put the code we want

        System.out.println("I am in myMethod1()");

    }

    public int myMethod2() throws RemoteException {

        return 5; //Here we put the code we want

    }

    public void anotherMethod() {

        //If we define another method, this can´t be called in a remote way unless we call it from the remote interface

    }
    public static void main(String[] args) {
        try {
            System.out.println("running main");
            MyRemoteInterface mir = new MyRemoteClass();
            InetAddress address = java.net.InetAddress.getLocalHost();
            System.out.println("host name : " + address.getHostName());

//Naming.rebind("//"+java.net.InetAddress.getLocalHost().getHostAddress() "/RMI_Test", mir);
            LocateRegistry.getRegistry().rebind("//"+java.net.InetAddress.getLocalHost().getHostAddress(), mir);

//System.out.println("Server started. Bound RMI test");

        } catch (Exception e) {

            System.err.println("exception: " + e);
        }
    }
}

The remote interface class:

package remotetests;

import java.rmi.*;

public interface MyRemoteInterface extends Remote {

    public void myMethod1() throws RemoteException;

    public int myMethod2() throws RemoteException;

}

The client class:

package remotetests;

public class MyRMIClient {

   public void MyRMIClient(String[] args){


        try{
            MyRemoteInterface mir = (MyRemoteInterface) java.rmi.Naming.lookup("//"+args[0] +":" +args[1]+"/RMITest");

            //MyRemoteInterface mir = (MyRemoteInterface) java.rmi.Naming.lookup("//127.0.0.1:1099/RMITest/");

            //We print myMethod1() as much as we get back myMethod2()

            int monitor = mir.myMethod2();

            for(int i=1;i<mir.myMethod2();i++){

                mir.myMethod1();

            }

        }catch (Exception e){

            e.printStackTrace();
        }  
    }
}*
user207421
  • 305,947
  • 44
  • 307
  • 483
Javier
  • 11
  • 1

0 Answers0