Javac does not create stubs for RMI

I am looking at RMI for a university project, and I ran into a problem. From a read ive, Java version 5 and above should automatically generate the necessary stub files (since I understand that an additional step was previously required).

However, after completing this tutorial here http://download.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html and compiling my classes using Javac, only I have standard class files no sign of my stub.

This is confirmed when I try to start my project, my application crashes that it cannot find stub files. Did I miss something?

NB, starting up java -versiongives me the following:

java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)
+3
source share
2 answers

I suppose you used something like

RemoteInterface stub =
(RemoteInterface) UnicastRemoteObject.exportObject(server);

on your server instead

RemoteInterface stub =
(RemoteInterface) UnicastRemoteObject.exportObject(server, 0);

Pay attention to two arguments on exportObject()- the second version returns a different type. It really matters to me.

+2
source

stubs are not needed or are not generated when> = 5.0 jvms. Perhaps some of the paths are wrong, in the manual it is not very clear how to configure directories / paths and where you start the material.

The following worked for me:

~ / tmp $ mkdir -p hello / example
~ / tmp $ vim hello / example / Hello.java [copy / paste the code of Hello.java here]
~ / tmp $ vim hello / example / Server.java [copy / paste the code of Server.java here]
~ / tmp $ vim hello / example / Client.java [copy / paste the code of Client.java here]
~ / tmp $ mkdir build
~ / tmp $ javac -d build / hello / example / *. java
~/tmp$ rmiregistry &
~/tmp$ java -classpath build -Djava.rmi.server.codebase=file:build/ example.hello.Server &
Server ready
~/tmp$ java  -classpath build  example.hello.Client
response: Hello, world!

- , , , -Djava.rmi.server.codebase.

+1

Source: https://habr.com/ru/post/1786519/


All Articles