How to get RMI to work - stub issues

K

Krystian

Hi

I've got a small application written in Java with RMI, but i can't get
it to work.
Here's my directory structure:

D:\Aplikacja\
-serwer\
com.krystian.info.jar
-klient\
test.jar


com.krystian.info.jar is a package with the server, which should send
some system info to the client.
test.jar is a package with client.
Here's what i do:
start rmiregistry
java -Djava.rmi.server.codebase=file:\\D:\Aplikacja\serwer\com.krystian.info -Djava.server.policy=java.policy -classpath D:\Aplikacja\serwer\com.krystian.info.jar com.krystian.info.Info info
parameter is the name to bind in the rmiregistry, the server starts
just fine and everything seems to be all right but:parameter is the name to bind in the rmiregistry. Unfortunately when
the client starts i get:
Exception in thread "main" java.rmi.UnmarshalException: error
unmarshalling retu
rn; nested exception is:
java.lang.ClassNotFoundException: com.krystian.info.Info_Stub
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at test.Test.main(Test.java:14)
Caused by: java.lang.ClassNotFoundException:
com.krystian.info.Info_Stub
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
......
but the stub is there!
jar cvf com.krystian.info.jar com\*
added manifest
adding: com/krystian/(in = 0) (out= 0)(stored 0%)
adding: com/krystian/info/(in = 0) (out= 0)(stored 0%)
adding: com/krystian/info/Info.class(in = 2475) (out= 1298)(deflated
47%)
adding: com/krystian/info/InfoI.class(in = 267) (out= 188)(deflated
29%)
adding: com/krystian/info/Info_Skel.class(in = 1747) (out=
978)(deflated 44%)
adding: com/krystian/info/Info_Stub.class(in = 3370) (out=
1647)(deflated 51%)
adding: com/krystian/info/libuxinfo.sl(in = 20480) (out= 3857)(deflated
81%)
adding: com/krystian/info/Param.class(in = 1286) (out= 735)(deflated
42%)
adding: com/krystian/info/UxInfo.class(in = 2257) (out= 1175)(deflated
47%)
adding: com/krystian/info/WinInfo.class(in = 2279) (out= 1158)(deflated
49%)
adding: com/krystian/info/wininfo.dll(in = 492375) (out=
137023)(deflated 72%)
adding: com/krystian/info/Wyjatek.class(in = 1820) (out= 974)(deflated
46%)

Could somebody explain me what do i do wrong?
I would appreciate it.

Best regards,
Krystian
 
N

Nigel Wade

Krystian said:
Hi

I've got a small application written in Java with RMI, but i can't get
it to work.
Here's my directory structure:

D:\Aplikacja\
-serwer\
com.krystian.info.jar
-klient\
test.jar


com.krystian.info.jar is a package with the server, which should send
some system info to the client.
test.jar is a package with client.
Here's what i do:
-Djava.server.policy=java.policy -classpath D
\Aplikacja\serwer\com.krystian.info.jar com.krystian.info.Info info
parameter is the name to bind in the rmiregistry, the server starts
just fine and everything seems to be all right but:
parameter is the name to bind in the rmiregistry. Unfortunately when
the client starts i get:
Exception in thread "main" java.rmi.UnmarshalException: error
unmarshalling retu
rn; nested exception is:
java.lang.ClassNotFoundException: com.krystian.info.Info_Stub
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at test.Test.main(Test.java:14)
Caused by: java.lang.ClassNotFoundException:
com.krystian.info.Info_Stub
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
.....
but the stub is there!

Could somebody explain me what do i do wrong?
I would appreciate it.

It's a while since I worked on RMI and rmiregistry, but I think you need to add
the jar to the classpath of rmiregisty if you want rmiregistry to be able to
supply the stubs to the client.
 
E

EJP

Nigel said:
It's a while since I worked on RMI and rmiregistry, but I think you need to add
the jar to the classpath of rmiregisty if you want rmiregistry to be able to
supply the stubs to the client.

No, it's the opposite: if you want the original classpath annotation to
be preserved, the registry must *not* have the classes available on the
classpath.

The OP seems to have left out a .jar on the end of the codebase.
 
K

Krystian

EJP said:
No, it's the opposite: if you want the original classpath annotation to
be preserved, the registry must *not* have the classes available on the
classpath.

The OP seems to have left out a .jar on the end of the codebase.

hmm...
how to do it?
How to add or remove a classpath from rmregistry?
I don't know how to do it with rmiregistry, i only know how to do it
with a java app.
I add the jar there, because the whole app is in jar and i start it
from there.

Best regards,
Krystian
 
E

EJP

Krystian said:
How to add or remove a classpath from rmregistry?
Don't.

I add the jar there, because the whole app is in jar and i start it
from there.

I agree but you have
-Djava.rmi.server.codebase=file:\\D:\Aplikacja\serwer\com.krystian.info

Surely this should be

-Djava.rmi.server.codebase=file:\\D:\Aplikacja\serwer\com.krystian.info.jar

???
 
K

Krystian

EJP said:
I agree but you have
-Djava.rmi.server.codebase=file:\\D:\Aplikacja\serwer\com.krystian.info

Surely this should be

-Djava.rmi.server.codebase=file:\\D:\Aplikacja\serwer\com.krystian.info.jar

???

I've tried, nothing has changed :/
Server starts normally, client doesn't:

java -Djava.security.policy=java.policy test.Test info
Exception in thread "main" java.rmi.UnmarshalException: error
unmarshalling retu
rn; nested exception is:
java.lang.ClassNotFoundException: com.krystian.info.Info_Stub
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at test.Test.main(Test.java:13)
Caused by: java.lang.ClassNotFoundException:
com.krystian.info.Info_Stub
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
 
E

EJP

This means that the registry had the classes on its classpath. Start it
from somewhere else other than the root directory of your package/class
hierarchy, i.e. somewhere where a classpath of '.' won't find your
..class files.
 
N

Nigel Wade

EJP said:
No, it's the opposite: if you want the original classpath annotation to
be preserved, the registry must *not* have the classes available on the
classpath.

It is a while since I used RMI... and memory fades.

I had a recollection that at one point I'd had a similar problem, and I thought
it was due to the rmiregisty not having access to the classes.
 
K

Krystian

Nigel said:
It is a while since I used RMI... and memory fades.

I had a recollection that at one point I'd had a similar problem, and I thought
it was due to the rmiregisty not having access to the classes.

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : (e-mail address removed)
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555


Thank You guys for reply,

I have started rmiregistry from a different location and now... server
won't start:
java -Djava.rmi.server.codebase=file:\\D:\Aplikacja\serwer\com.krystian.info.jar -Djava.server.policy=java.policy -classpath D:\Aplikacja\serwer\com.krystian.info.jar com.krystian.info.Info info info
Exception in thread "main" java.rmi.ServerException: RemoteException
occurred in
server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments;
nested excep
tion is:
java.lang.ClassNotFoundException: com.krystian.info.Info_Stub
at
sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:352
)
at
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:207)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
60)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
..java:701)
at java.lang.Thread.run(Thread.java:534)
at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:247)

Now i really have no idea what's going on :/
Damn... this should be so easy... :/
 
K

Krystian

Krystian said:
Thank You guys for reply,

I have started rmiregistry from a different location and now... server
won't start:

Exception in thread "main" java.rmi.ServerException: RemoteException
occurred in
server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments;
nested excep
tion is:
java.lang.ClassNotFoundException: com.krystian.info.Info_Stub
at
sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:352
)
at
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:207)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
60)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:701)
at java.lang.Thread.run(Thread.java:534)
at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:247)

Now i really have no idea what's going on :/
Damn... this should be so easy... :/

LOL.

i think i solved it...
the problem was with file:// instead of file:/// ;>

Now i've got a new issue with client:

java.lang.ClassCastException
at test.Test.main(Test.java:13)
Exception in thread "main"

The line is:
InfoI t = (InfoI)Naming.lookup(arg[0]);

where InfoI is the name of the interface i send trough RMI.
Have You got any idea what's causing it?

I've tried to change arg[0] to "info" but it doesn't change anything :/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top