aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI: Stubs & Java 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI: Stubs & Java 6" Watch "RMI: Stubs & Java 6" New topic
Author

RMI: Stubs & Java 6

Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Hi folks, I'm into my final testing and I have hit a problem , just wondering if anyone has any pointers on avenues to investigate.

My problem is with RMI and stubs. As we all know, since Java 5you don't need to generate stub classes any more.

I have been testing my application throughout my development in Eclipse - so I am pretty sure that it was working without any stubs being generated by me. Although I'm not 100% certain that I was always testing across a network.

I am now testing across a network - server on one machine, client on another. For this testing I am using the built JAR. Everything is working fine. But I do generate the stubs as part of creating my final jar.

Now, in order to do some debugging, I launched my network client from Eclipse. I then attempted to connect to a server on another machine. Up pops this error:

I was not a happy camper!

As a first step of investigation I decided to remove the step for my build process so that the stubs are not generated in the final JAR. I then tested using this JAR as my network client. Unfortunately I am getting the same error here.

Now I am a little confused. Because I am definitely using Java 6. Any ideas?

My classes are set up like this:

To connect to my remote service within my GUI code I am doing this:


SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

I just tested the scenario of my server running in Eclipse and my network client running in Eclipse. This works fine. No issue with the RMI stubs not being found.

I'm not quite sure what the problem is. But it sounds like I have done something wrong with my RMI set up. Because when I generate the stub classes everything works fine.

So just to summarise:

1) This works: Server running on my local machine in Eclipse. Network client running on my local machine in Eclipse.
2) This doesn't work: Server running on another machine from my built JAR. Client running on my machine from built JAR (without stub files generated).
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

I've just done a further test. I built my final JAR and did not include the stub files. I ran the server on my machine from the JAR. I ran the client on my machine from the JAR. The client successfully connected to the server without any exception being thrown about stub classes not being available.
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Final test:

  • I built my final JAR and did not include the stub files.
  • I ran server using this JAR on another machine
  • I ran the client using this JAR on my machine
  • The client successfully connected to the server!


  • Phewwwwwww! Panic over ...glad I had this little chat with myself.
    Roberto Perillo
    Bartender

    Joined: Dec 28, 2007
    Posts: 2266
        
        3

    Sean Keane wrote:Phewwwwwww! Panic over ...glad I had this little chat with myself.


    Good to know! I wouldn't be able to help you on this because, as you mentioned, generating stubs are history nowadays, so I didn't generate them!


    Cheers, Bob "John Lennon" Perillo
    SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
    Sean Keane
    Ranch Hand

    Joined: Nov 03, 2010
    Posts: 581

    Just in case it wasn't clear what my problem was. My server was running with a JAR that contained stub files that I generated using rmic. My client was running without any stub files. I don't understand fully why this did not work.

    I can take a guess that when the server is running with stub files and the client connects to it, then this causes dynamic loading to occur. This would result in the client attempting to download the stub file. That is why I am seeing a "error unmarshalling" in the Exception.

    In order for dynamic loading to occur you need to set up a security policy and security manager. Which obviously I do not do as our assignment is not meant to use dynamic class loading. My Exception message hints at this being the problem too with "no security manager" in the Exception message.

    All of that is just an semi-educated guess. What I do know for sure is:

  • If the server is running with stub files and the client is running with stub files. It works.
  • If the server is running with no stub files and the client is running with not stub files. It works.



  • Ray Dawson
    Ranch Hand

    Joined: Sep 16, 2011
    Posts: 75
    Do we need to generate stubs now using the rmic ?
    Roberto Perillo
    Bartender

    Joined: Dec 28, 2007
    Posts: 2266
        
        3

    Ray Dawson wrote:Do we need to generate stubs now using the rmic ?


    Well champ, I didn't generate them. A lot of other people also didn't generate them. We all passed.
    Ray Dawson
    Ranch Hand

    Joined: Sep 16, 2011
    Posts: 75
    Roberto Perillo wrote:
    Ray Dawson wrote:Do we need to generate stubs now using the rmic ?


    Well champ, I didn't generate them. A lot of other people also didn't generate them. We all passed.





    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5408
        
      13

    Not generating the stubs is violating a must requirement, so you could fail. But already a whole bunch of people didn't generate them and passed, so it's not an issue anymore (and it would be nice if Oracle updated the assignment instructions, so you are not breaking a must requirement anymore and you don't need to document this decision in choices.txt)


    SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
    http://www.javaroe.be/
    Sean Keane
    Ranch Hand

    Joined: Nov 03, 2010
    Posts: 581

    I must double check my instructions. But from what I remember there is no mention of stubs in them.
    Sean Keane
    Ranch Hand

    Joined: Nov 03, 2010
    Posts: 581

    Here are what my instructions say about RMI:
    You must not require the use of an HTTP server.
    You must not require the installation of a security manager.
    You must provide all classes pre-installed so that no dynamic class downloading occurs.
    You must use RMI over JRMP (do not use IIOP)

    No mention of stubs. So not a must requirement?

    But from a quick read of the forum it seems that the automatic generation of stubs at runtime is dynamic class downloading! So it sounds like that the generation of stubs is a must requirement.

    Has anyone failed because they did not generate stubs?
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5408
        
      13

    Sean Keane wrote:No mention of stubs. So not a must requirement?

    I think it's part of the "You must provide all classes pre-installed" part, but not sure about that one.

    Sean Keane wrote:Has anyone failed because they did not generate stubs?

    No. Roberto was one of the 1st people to submit without stub generation (and document this decision) and passed. Many people have followed that approach and as far as I know nobody has failed for not generating them. I don't know if everyone documented this decision, so I certainly would mention it in choices.txt.
    Ray Dawson
    Ranch Hand

    Joined: Sep 16, 2011
    Posts: 75
    I run the command rmiregistry

    Does it generates stubs ??
    Sean Keane
    Ranch Hand

    Joined: Nov 03, 2010
    Posts: 581

    Roel De Nijs wrote:
    Sean Keane wrote:No mention of stubs. So not a must requirement?

    I think it's part of the "You must provide all classes pre-installed" part, but not sure about that one.


    I did a good bit of research into RMI so I would be interested in finding out an answer to whether the omitting of generated stubs results in dynamic class loading.

    From reading a few threads on the forum it appears that people included stubs as they thought not doing so would result in dynamic class loading. But you mention another requirement Roel which could possibly be the reason why people included stubs.

    The example I put together on this thread here is an example of dynamic class loading. The client needs a class at runtime that it doesn't have. Through the use of RMI and a Webserver, the client downloads the class from the Webserver. This is definitely dynamic class loading

    I genuinely don't know the answer. But hope to find out. I have put a question up here on the Distributed Java forum to see if any of the guys with more expertese in this area can help.
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5408
        
      13

    Ray Dawson wrote:I run the command rmiregistry

    Does it generates stubs ??

    If you completely read this topic you'll find the answer to your question (or is even that too much effort?)
     
    Don't get me started about those stupid light bulbs.
     
    subject: RMI: Stubs & Java 6