• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Remote Deployment with RMI

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am reading HeadFirst Java, I am at Remote Deployment with RMI Chapter. I can't seem to run the program for some reason unknown to me. I am new to JAVA and would appreciate detailed answers.
Following are the classes involved : MyRemoteImpl.class, MyRemote.class and MyRemoteClient.class.

Here's how it goes:

MyRemoteImpl.class code goes like that :


MyRemote.class code goes like this :



both the classes are in the folder called Server.

Then I open a new cmd terminal and type : rmic MyRemoteImpl which gives a warning message :
"Warning: generation and use of skeletons and static stubs for JRMP
is deprecated. Skeletons are unnecessary, and static stubs have
been superseded by dynamically generated stubs. Users are
encouraged to migrate away from using rmic to generate skeletons and static
stubs. See the documentation for java.rmi.server.UnicastRemoteObject."


But it does generate the Stub file, although according to the book it must generate Skeleton file too which it doesn't.

Now I copy the stub and MyRemote.class file to a different folder called Client where I'd have MyRemoteClient.class file too.

Now I opened another terminal and from the directory where I have the Stub class, MyRemote class and MyRemoteImpl class I run the command : rmiregistry.

Then I opened another terminal and ran the service: java MyRemoteImpl
when I run the MyRemoteImpl service I get the following error:

"C:\Harsh\Java\Server>java MyRemoteImpl
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: MyRemoteImpl_Stub
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:420)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:268)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:177)
at MyRemoteImpl.main(MyRemoteImpl.java:17)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: MyRemoteImpl_Stub
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:410)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:268)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: MyRemoteImpl_Stub
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1221)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:453)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:186)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:637)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:264)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:214)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
... 15 more"


then I go to client folder I compile the MyRemoteClient.java file so that I have the three classes in that folder namely: MyRemoteClient class and Stub and MyRemote class which I copied earlier. Now when I run MyRemoteClient class from another terminal I get the following message:
"C:\Harsh\Java\Client>java MyRemoteClient
java.rmi.NotBoundException: RemoteHello
at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:166)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:410)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:268)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at MyRemoteClient.go(MyRemoteClient.java:10)
at MyRemoteClient.main(MyRemoteClient.java:6)

C:\Harsh\Java\Client>"


I am assuming the client is not running because it is unable to connect to the stub in the registry at the server end because the service is not running for which the stub might be the culprit.

I am running the program in a single machine so my machine is acting as both the server and the client.

Could I please know where I am going wrong and what does that warning tells me when I run RMIC tool, I did see through the documentation of UniCastRemoteObject but I couldn't relate anything to the warning (maybe that's because I am a total amateur right now)

Any help would be greatly appreciated.
Thank You
Harsh
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't read Head First Java, but it looks like even its second edition was back in 2005, which means its content is rather outdated.
The last time I touched RMI was 5 years ago, and even then, rmic was unnecessary.

The rmic warning is just a warning - not an error - that says it's unnecessary. Given a Remote interface, the RMI framework is capable of
creating a stub object on demand in memory without you having to create a _Stub.java file using rmic.

Unfortunately, even Oracle's own latest Java8 tutorial on RMI doesn't seem to be updated from the Java1.4 days!
So there's no alternative up-to-date tutorial I could find to point you towards. We'll just have to wing it in this thread itself step by step.

The first problem I can see in your procedure is not even specific to RMI. Whenever you run into a ClassNotFoundException, it means you've missed out something in your classpath:
In your commandline:

there is no classpath at all. Even if all classes are in current directory, you still need to give it a classpath like so:


Do this, retry and reply back with the result. The rmic problem we'll tackle later.
 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:I haven't read Head First Java, but it looks like even its second edition was back in 2005, which means its content is rather outdated.
The last time I touched RMI was 5 years ago, and even then, rmic was unnecessary.

The rmic warning is just a warning - not an error - that says it's unnecessary. Given a Remote interface, the RMI framework is capable of
creating a stub object on demand in memory without you having to create a _Stub.java file using rmic.

Unfortunately, even Oracle's own latest Java8 tutorial on RMI doesn't seem to be updated from the Java1.4 days!
So there's no alternative up-to-date tutorial I could find to point you towards. We'll just have to wing it in this thread itself step by step.

The first problem I can see in your procedure is not even specific to RMI. Whenever you run into a ClassNotFoundException, it means you've missed out something in your classpath:
In your commandline:

there is no classpath at all. Even if all classes are in current directory, you still need to give it a classpath like so:


Do this, retry and reply back with the result. The rmic problem we'll tackle later.




Ok so I typed in :



It showed me the exactly same results as before which is :


then I typed in :



and got this error again:



How is it not being able to locate the Stub class even after running it from the same directory where the class is and also mentioning it the cmd command?
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a file called "MyRemoteImpl_Stub.class" under C:\Harsh\Java\Server?
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, you should get in the habit of using packages for all your classes. Not sure if it makes a difference here, but in some circumstances it does.
 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:Is there a file called "MyRemoteImpl_Stub.class" under C:\Harsh\Java\Server?



Yes it is present there .
 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Also, you should get in the habit of using packages for all your classes. Not sure if it makes a difference here, but in some circumstances it does.



You're right, but to avoid complexity and sake of testing the concept quickly I refrained my self from using the packages. I know it is always a good idea to use packages.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then perhaps this exception is actually on the rmiregistry end, not the server end, when it tries to unmarshall the object passed but can't do so because it doesn't know where to find the _Stub.class.


In the console running rmiregistry, can you stop it, "set CLASSPATH=the directory where the _Stub.class is located"?
If memory serves me right, you can also do "rmiregistry -J-cp <dir_of_Stub.class>" instead of setting env variable.
And restart rmiregistry in the same console.
 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:Then perhaps this exception is actually on the rmiregistry end, not the server end, when it tries to unmarshall the object passed but can't do so because it doesn't know where to find the _Stub.class.


In the console running rmiregistry, can you stop it, "set CLASSPATH=the directory where the _Stub.class is located"?
If memory serves me right, you can also do "rmiregistry -J-cp <dir_of_Stub.class>" instead of setting env variable.
And restart rmiregistry in the same console.



C:\Harsh\Java\Server>rmiregistry -J-cp C:Harsh/Java/Server/MyRemoteImpl_Stub.class showed the error :

Error: Could not find or load main class C:Harsh.Java.Server.MyRemoteImpl_Stub.class
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, <dir_of_Stub.class> like "C:\Harsh\Java\Server\". Classpath contains directories or JAR files, never .class files.
 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:No, <dir_of_Stub.class> like "C:\Harsh\Java\Server\". Classpath contains directories or JAR files, never .class files.



Ya ya, i understood , i did that only.. still gave that error.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No idea then, sorry.
 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:No, <dir_of_Stub.class> like "C:\Harsh\Java\Server\". Classpath contains directories or JAR files, never .class files.



This is what I get:
C:\Harsh\Java\Server>rmiregistry -J-cp C:\Harsh\Java\Server\MyRemoteImpl_Stub.class
Error: Could not find or load main class C:\Harsh\Java\Server\MyRemoteImpl_Stub.class
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic