• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

I am getting ClassNotFoundException for stub file

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am trying an RMI demo given at Sun tutorial http://java.sun.com/docs/books/tutorial/rmi/running.html. But, facing
an exception whehn I run the client.
java.rmi.UnmarshalException: error unmarshalling return; nested excepti
java.lang.ClassNotFoundException: ProductImpl_Stub
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at ProductClient.main(ProductClient.java:32)
Caused by: java.lang.ClassNotFoundException: ProductImpl_Stub
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Sourc
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 3 more
Can anybody give some suggestions about why the server is not finding Stub files for downloading them to client ?
Thanks,
Sachin
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sachin,
This is just a guess, but you may need to assign a value to the java.rmi.server.codebase (RMI) property. You can find more details in the java.rmi Properties page of the java documentation.
Good Luck,
Avi.
 
Sachin Joshi
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Avi Abrami:
Sachin,
This is just a guess, but you may need to assign a value to the java.rmi.server.codebase (RMI) property. You can find more details in the java.rmi Properties page of the java documentation.
Good Luck,
Avi.



Hi Avi
Thanks for the reply.
Your guess is right. I was mssing "codebase" attribute while starting the client. But, still now also I am facing the same error. Some details of my application are like this :->
Server - > Solaris 2.6
1. Product.class - Remote Interface
2. ProductImpl.clas - Remote Interface Impl
3. ProductServer.class - RMI Server
4. Stubs classes
Starting server as :-> java -Djava.rmi.server.codebase -Djava.security.policy <ClassFileName>

Client -> Windows 2000
1. Product.class - Remote Interface
2. ProductClient.class - >Requesting client
Starting client as :-> java -Djava.rmi.server.codebase -Djava.security.policy <ClassFileName>
Please suggeet if you get any hint.
Thanks,
Sachin
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please make sure you search for UnmarshalException or "error unmarshalling return" or something else related to the problem in this forum. I know that some form of this question has been asked here about a buzillion times and I think at least some of them have suggestions and answers attatched. I'm not bashing your asking the question, I just want to make sure you searched for the answer as well. Usually its faster than waiting for a good reply to answer your question.
Chris
 
Sachin Joshi
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chris Shepherd:
Please make sure you search for UnmarshalException or "error unmarshalling return" or something else related to the problem in this forum. I know that some form of this question has been asked here about a buzillion times and I think at least some of them have suggestions and answers attatched. I'm not bashing your asking the question, I just want to make sure you searched for the answer as well. Usually its faster than waiting for a good reply to answer your question.
Chris


Hi Chris,
Thanks for the nice suggestion.
I will surely do that and will post my reply if I get the solution.
Sachin
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sachin,
Here is my next guess: The "ProductImpl_Stub.class" file needs to be located on the client (as well as on the server). You need to copy that file to your client.
Good Luck,
Avi.
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Avi's got it. For "normal" RMI, the client needs to have access to the _Stub file. I don't think the server actually needs it, but it does need the ProductImpl.class file itself. I think it generates the skeleton file itself on the fly by using reflection. You could try it and see. Of course if you provede the _Stub file to the server also, its not going to care I don't think.
Chris
 
Sachin Joshi
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chris Shepherd:
I think Avi's got it. For "normal" RMI, the client needs to have access to the _Stub file. I don't think the server actually needs it, but it does need the ProductImpl.class file itself. I think it generates the skeleton file itself on the fly by using reflection. You could try it and see. Of course if you provede the _Stub file to the server also, its not going to care I don't think.
Chris


Hi Chris and Avi
I agree to your idea of copying the stub files to the client. But then my interpretation was different.
I was trying like, when my RMI client makes a request for remote object, the Stub class will be
downloaded from the location(on the server) that is specified in the codebase attribute while starting the client.
Also according to the JGuru RMI tutorial, you can give either of the 3 protocols file, ftp or http in the codebase attribute.
I am using file protocol in my example case. I have a question here. Is it MANDATORY to have Http or Ftp server application
running on my RMI server side, so that I will copy the stub files in some public directory of this server and then by specifiying
this public directory in the codebase of client I can get the stub ?
Also, in my application case, there could be more than 1 server machines and only 1 client. This client will send remote requests
to get the information from the server machines. The implementations of remote interface on each of these server machines
could be different though the method signature will be same. Now by taking your idea of copying the stub file to the client side,
in the case I explained above, if I copy only stub file on client side will it be ok or I need to copy the stub files for each server
implementations ?

Please suggest.
Thanks,
Sachin
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys
I was getting this error as well and read this post in the hope of it shedding some light. Needless to say it didn't help. But I have subsequently found a solution to the problem. I have no idea why it works, but it does.
I had the _stub file in the classpath, And I kept getting the ClassNotFoundException whenever I tried starting the server. I had started the rmiregistry in a seperate window. So for some reason I stopped the rmiregistry and added the following line to my server class, before the bind/rebind Runtime.getRuntime().exec("rmiregistry 2020"); and the error disappeared into thin air.
Like I said, I have no idea why it is now working, but I do know that it is at least working now. So if you read this, try it, and hopefully it works for you too. good luck.
cheers
Darryl
PS: your server does need the stub by the way...
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting Darryl. I think it must have been some sort of classpath error or something. By starting it within your code, it may have used the same classpath info as your code was using. There is actually an even easier way to start your registry without having to use an external .exec command. try this instead:

Sachin, I know that something like that is possible where you actually don't have to have the _stub on your client machine to start with, but I've never had to deal with that issue so I don't know exactly how to do it. It is NOT mandatory that your server be running a http/ftp server to operate that way, but your stub/file must be downloadable from somewhere. Even if its on a totally different host/site. All you care about is collecting the needed file so you know what interface you wil be using. You also have to make sure that it is kept current with the same one that your server is using or I think it might possibly fail.
As to the different implementations of the interface, it doesn't matter what you do on the server side of the interface. As long as it matches the interface stub the client is working with, your client/server interface should work fine.
HTH
Chris
 
Sachin Joshi
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chris Shepherd:
Interesting Darryl. I think it must have been some sort of classpath error or something. By starting it within your code, it may have used the same classpath info as your code was using. There is actually an even easier way to start your registry without having to use an external .exec command. try this instead:

Sachin, I know that something like that is possible where you actually don't have to have the _stub on your client machine to start with, but I've never had to deal with that issue so I don't know exactly how to do it. It is NOT mandatory that your server be running a http/ftp server to operate that way, but your stub/file must be downloadable from somewhere. Even if its on a totally different host/site. All you care about is collecting the needed file so you know what interface you wil be using. You also have to make sure that it is kept current with the same one that your server is using or I think it might possibly fail.
As to the different implementations of the interface, it doesn't matter what you do on the server side of the interface. As long as it matches the interface stub the client is working with, your client/server interface should work fine.
HTH
Chris



Hi Chris
Thanks for the reply.
I tried with different implementations at server side. It is working fine. Currently the whole thing is working by copying the stub on client side, but anytime if you come across some hint for not having the stub on client side then please let me know.
Thanks to Avi too for his replies.
Sachin
 
darryl nortje
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howzit Chris and Sachin,
I think I found out why it worked. Let me explain, when I was trying to get the rmi server up, I was starting the rmiregistry external to the server in the command line. This was giving me the not bound exception. I then put the exec line in my server itself, which at the time was a dummy server, in the default package (ie no packed). So what it did is start the rmiregistry in the root directory of the application, so that from the root, it could then find com.whatever_stub.
When I structured my dummy application properly and put the server class in a package, suddenly the error NotBoundException returned. so in essence you're right. It is due to a classpath problem, which can be solved in two ways as I have found out recently.
1) in the command prompt, set the classpath to reference the root directory of your application, or start the rmiregistry from the root of your application.
2) there is a solution using the codebase. you have to set the codebase to be exactly that, the base/root of your application, which I think is similar to setting your classpath to the root.
Either way, I think I have now solved the problem on my side for good. I have an environment variable for my application, that points to the root of my app, and I start the rmiregistry from my server, but instead of running the rmiregistry, I run a batch file that starts the rmiregistry using the environment variable.
Hope this helps.
cheers
Darryl
 
I am Arthur, King of the Britons. And this is a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic