wood burning stoves 2.0*
The moose likes Distributed Java and the fly likes dynamic code downloading problem with RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "dynamic code downloading problem with RMI" Watch "dynamic code downloading problem with RMI" New topic
Author

dynamic code downloading problem with RMI

keisin syu
Greenhorn

Joined: Dec 04, 2002
Posts: 25
My directory structure:
server:
C:\rmisample\server\
..\public\classes\engine\ComputeEngine_Stub.class
..\ComputeEngine_Skel.class
..\src\compute.jar
..\engine\ComputeEngine.class
client:
C:\rmisample\client\
..\public\classes\client\Pi.class
..\src\compute.jar
..\client\ComputePi.class
..\Pi.class
firstly, I start rmiregistry:
1) set classpath=
--I want to unset classpath, is right?
2) start rmiregistry
2. start server of engine.ComputeEngine int directory C:\rmisample\server\src>
java -classpath compute.jar;.
-Djava.rmi.server.codebase=file:/c:\rmisample\server\public\classes/
-Djava.rmi.server.hostname=localhost
-Djava.security.policy=java.policy
engine.ComputeEngine
3. run client program client.ComputePi in directory C:\rmisample\client\src>
java -classpath compute.jar;.
-Djava.rmi.server.codebase=file:/c:\rmisample\client\public\classes/
-Djava.security.policy=java.policy
client.ComputePi 10.194.72.80 20
it will work if they are run on the same PC.
but if I move the client part to the other one,
i cannot run the client and get the exception like this:
ComputePi exception: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: engine.ComputeEngine_Stub
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: engine.ComputeEngine_Stub
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at client.ComputePi.main(ComputePi.java:14)
if I copy the stub of server to the classpath of client,
it will work with two PCs.
this exception looks like from the setting of classpath of rmiregistry
but WHY? is it right i execute "set classpath=" to unset classpath?
(I'm using WindowsXP)
[ February 27, 2003: Message edited by: keisin syu ]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
To dynamically download the stubs, you need to have an HTTP server that is able to serve the subs upon request. That means that you must either write your own server or hope that the assessor has it running, in which case you still need to configure it. Both of these propositions are very risky. The consensus in this forum is that you don't need to implement dynamic code downloading. Simply package your stubs with the client, and you are done.
Eugene.
keisin syu
Greenhorn

Joined: Dec 04, 2002
Posts: 25
thanks Eugene!
and I have another question about this topic, because the server need class Pi for ComputeEngine, and will upload Pi.class to the sever side.
is done by rmiregistry? why can it be done by the rmiregistry, but the stub is not?
keisin syu
Greenhorn

Joined: Dec 04, 2002
Posts: 25
I'm really doubting about the option of classpath now!
today I want to start sever engine.ComputeEngine, and got the exception saying that classloader cannot find the class of compute/Compute? how could it happen like this?
I'm using the same command as yesterday's, but it work smoothly yesterday!!
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

and I have another question about this topic, because the server need class Pi for ComputeEngine, and will upload Pi.class to the sever side.

Keisin,
This forum is to discuss the Java Developer Certification only, and your question would be better answered in the Sockets and Internet Protocols forum.
Eugene.
Diarmuid TelcoEngineer
Greenhorn

Joined: Feb 20, 2006
Posts: 2
This problem cost me a lot of time too!

The basic Java tutorial on RMI does not make it clear that although RMI is capable of transporting an INSTANCE of a class via RMI, RMI does NOT transport a CLASS DEFINITION FILE.

This is much clearer in http://java.sun.com/j2se/1.3/docs/guide/rmi/codebase.html

RMI supplies a URL which specifies which protocol to use for the server and client codebase.
Option 1: file:/C:\mydisk\mycodebase\/
Option 2: http://MYWEBSERVER/rmiCodebase/
Option 3: ftp://MYFTPSERVER

Note that the protocol in option 1 (which you have been using) assumes that the server and client are co-resident.
Option 2 requires that you setup a webserver on BOTH client and server.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Please keep to the topic of this forum SCJD. Dynamic code downloading in RMI is not currently allowed in an SCJD assignment solution.

Closing this topic and moving to our Distributed Java forum.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dynamic code downloading problem with RMI
 
Similar Threads
PLEASE HELP
Connectin remote DB exception
Can not get remote object _stub
dynamic code downloading problem with RMI
rmi Unknown host