java - Running RMI Server, got errors with marshalling arguments and class not found -


i'm following tut show how create rmi project.

but when run server site, has errors. when run: rmic calculatorimpl, creates stub, dont see ske. enter image description here

this log when run rmic calculatorimpl:

warning: generation , use of skeletons , static stubs jrmp deprecated. skeletons unnecessary, , static stubs have been superseded dynamically generated stubs. users encouraged migrate away using rmic generate skeletons , static stubs. see documentation java.rmi.server.unicastremoteobject. 

and when run calculatorserver:

java.rmi.serverexception: remoteexception occurred in server thread; nested exception is: java.rmi.unmarshalexception: error unmarshalling arguments; nested exception is: java.lang.classnotfoundexception: calculatorimpl_stub 

this code:

file calculatorserver:

public class calculatorserver { public calculatorserver() {     try {         calculator c = new calculatorimpl();         naming.bind("rmi://localhost:1099/calculatorservice", c);     } catch (exception e) {         system.out.println("trouble: " + e);     } }  public static void main(string args[]) {     new calculatorserver(); } } 

file calculator:

public interface calculator extends remote { public long add(long a, long b)         throws java.rmi.remoteexception; } 

and file calculatorimpl:

public class calculatorimpl extends     java.rmi.server.unicastremoteobject implements calculator { public calculatorimpl()         throws java.rmi.remoteexception {     super(); }  public long add(long a, long b)         throws java.rmi.remoteexception {     return + b; } } 

and calculatorclient in project:

public class calculatorclient {  public static void main(string[] args) {     try {         calculator c = (calculator)                 naming.lookup(                         "rmi://localhost/calculatorservice");         system.out.println( c.add(4, 5) );      }     catch (malformedurlexception murle) {         system.out.println();          system.out.println(                 "malformedurlexception");         system.out.println(murle);     }     catch (remoteexception re) {         system.out.println();         system.out.println(                 "remoteexception");         system.out.println(re);     }     catch (notboundexception nbe) {         system.out.println();         system.out.println(                 "notboundexception");         system.out.println(nbe);     }     catch (             java.lang.arithmeticexception                     ae) {         system.out.println();         system.out.println(                 "java.lang.arithmeticexception");         system.out.println(ae);     } } } 

so please me.tks all!

summarizing comment chain.

what essential registry should aware of server stub. in order happen, there 2 options. option 1 registry , server share same vm. can achieved through

adding locateregistry.createregistry() in beginning of server main class.

option 2

two configure server use automatic download of stub files can achieved through java.rmi.server.codebase

example command

java -cp c:\home\ann\src;c:\home\ann\public_html\classes\compute.jar      -djava.rmi.server.codebase=file:/c:/home/ann/public_html/classes/compute.jar      -djava.rmi.server.hostname=mycomputer.example.com      -djava.security.policy=server.policy         engine.computeengine 

this taken https://docs.oracle.com/javase/tutorial/rmi/running.html


Comments