java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: ServicesTableau

為{幸葍}努か 提交于 2021-02-18 05:48:06

问题


I need your help around JAVA RMI, i developped a sample program used to sort table. but i got this exception:

Erreur RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: ServicesTableau

and this is my Server source code :

public class Serveur {
    public static void main(String args[]) {

        try {

            System.out.println("Server start ...");
            ServicesTableauImpl od = new ServicesTableauImpl();
            String url = "rmi://" + args[0] + "/ServicesTableauImpl";
            System.out.println("Passe");
            Naming.rebind(url, od);
            System.out.println("Attente d'invocations de client / CTRL-C pour stopper");
        } catch (Exception e) {
            System.out.println("Erreur " + e.getMessage());
        }
    /*
    catch(java.net.MalformatedURLException e){
    System.out.println("Mauvais nom de serveur");
    System.exit(1);
    }
    catch(RemoteException e){
    System.out.println("Pas de Rmiregistry");
    System.exit(1);
    }
    */
    }
}

回答1:


That class isn't available on the CLASSPATH of the RMI Registry. The simplest way to fix it is to start the Registry in the same JVM, via LocateRegistry.createRegistry(). Store the result in a static field.




回答2:


This happened to me because I didn't run rmiregistry in the same directory as the server.




回答3:


I spent a few hours to successfully start the simple example form Orcale!

Hope could help you

First, I run the program on Windows

I totally copy the code from here

but i delete the package and put that three .class file together for the convince

and if you are not familar with this i hope you'd better do it, too

because when package get in, the problem will be more complicated

There are three steps to do:

1.start rmiregistry

start rmiregistry -J-Djava.class.path=./

it is for "remote interface definition"

so that the rmiregistry can find the class

then solve the ClassNotFoundException

2.run server

start java Server

then you can see the output:

Server ready

3.run client

java Client

output:

response: Hello, world!

then talk about how to deal with package

Usually the Server.class and interface.class---"remote interface definition"

should be in the same package

and you need to know how to run the .class with package

java {packagename}.Server

the classpath default is "./"

and package declare will help to locate the interface.class which is needed for Server.class

so we don't need to separately set -cp

BTW, if you try set the real classpath, you will get error instead

As for "start rmiregistry"

it has no default classpath

so we need to set it

and it should be the same as the classpath's default value "./"




回答4:


In some cases, you need to move you rmi clients code (interface and main) to default package. Repeate it for server side. It can solve you problem(work with packaging in rmi is not so obvious).




回答5:


This error is because of not writing security manager code, because of which the class can't get loaded. So make sure you add code for the security manager. 
If the compiler doesn't find the security manager then create a new one.Add the code in main method.

if (System.getSecurityManager() == null) then
    System.setSecurityManager(new RMISecurityManager())


来源:https://stackoverflow.com/questions/14071885/java-rmi-unmarshalexception-error-unmarshalling-arguments-nested-exception-is

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!