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

6

13

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);
    }
    */
    }
}
Lezlielg answered 28/12, 2012 at 15:34 Comment(2)
Is this class ServicesTableauImpl available in class path?Cushat
@PradeepSimha The missing class is ServicesTableau, not ServicesTableauImpl. Read the exception.Baucom
B
19

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.

Baucom answered 28/12, 2012 at 23:58 Comment(2)
I'm working under Linux, thanks for ur response (i used rmiregistry it work fine now)Lezlielg
Linux doesn't make any difference to the answer.Baucom
I
11

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

Instate answered 21/2, 2019 at 12:7 Comment(1)
This helped me solve the issue even in 2023... Hopefully they update the oracle page.Institutionalism
P
0

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 "./"

Prynne answered 8/11, 2020 at 8:46 Comment(1)
As the classpath default is ., as you correctly state, explicitly specifying it cannot possibly be part of the solution. There is no need for the server class and remote interface to be in the same package. Answer is just waffle.Baucom
G
-1

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).

Gonagle answered 14/2, 2017 at 15:14 Comment(1)
Using the default package doesn't even work properly since Java 1.4. You certainly have to use the same package, i.e. strictly speaking the same class, at client and server, but it should not be the default package.Baucom
B
-1

The answer is for IDE based project.

you need to 'start rmiregistry' from with in the build folder.

for example: in Intellij

  1. open terminal inside 'target -> classes' folder
  2. run 'start rmiregistry'
  3. then run your server code using intellij

for eclipse I hope its build folder

Binucleate answered 10/3, 2021 at 16:26 Comment(2)
Do you mean to say "This answer is for IDE based projects?"; if not, which answer are you referring to?Orchitis
Pointless answer. This will not work where the application is deployed.Baucom
D
-3

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())
Dolt answered 9/10, 2014 at 3:22 Comment(1)
No it isn't. It is due to the class not being found. You need to read the entire exception. It would only be due to the lack of a security manager if he was using the RMI codebase feature, which isn't stated.Baucom

© 2022 - 2024 — McMap. All rights reserved.