开发者

javac not creating stubs for RMI

Im looking into RMI for a university project, and ive run into a bit of a problem. From what ive read, java version 5 and up should generate the necessary stub files automatically (as i understand there was previously an additional step required).

However after following this tutorial here http://download.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html and com开发者_开发百科piling my classes with Javac, ive only got the standard class files, no sign of my stub files.

This is confirmed when i try and run my project, my application crashes saying that it cant find any stub files. Am i missing something?

NB, running java -version gives me this:

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)


I believe you used something like

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

in your server, instead of

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

Note two arguments to exportObject() -- second version returns different type. It indeed make difference for me.


stubs arn't needed or generated on >= 5.0 jvms. It might be that some of the paths are wrong, the tutorial isn't very clear on all how to set up the directories/paths and where you run stuff from.

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!

The important part here is which directory you stand in when building and running stuff, as well as passing the proper directories to classpath and -Djava.rmi.server.codebase.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜