O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating Stubs and Skeletons

Now that we’ve written and compiled the servers, we need to generate stubs and skeletons. This is easy; we simply need to invoke the RMI compiler, rmic. Here, for example, is the invocation of rmic we use to generate stubs and skeletons for the bank server:

rmic -keep -d d:\classes com.ora.rmibook.chapter8.Account_Impl com.ora.rmibook 
    chapter8.Account_Impl2

Tip

rmic works by generating Java source code for the stubs and skeletons and then compiling those Java files. The -keep flag simply tells rmic to save the source code to .java files.

rmic takes a .class file and creates a pair of companion files, a stub and a skeleton, in the same package as the .class file. Thus, the above invocation of rmic actually generates four Java class files:

com.ora.rmibook.chapter8.Account_Impl_Skel
com.ora.rmibook.chapter8.Account_Impl_Stub
com.ora.rmibook.chapter8.Account_Impl2_Skel
com.ora.rmibook.chapter8.Account_Impl2_Stub

There’s an interesting subtlety here. rmic requires the actual implementation’s class files. It seems, at first glance, that the compiled interface files might suffice. However, the designers of RMI decided that the stubs and skeletons should satisfy the following two requirements:

  1. There should be a unique stub/skeleton pair per server, so we can do things such as register the server in the naming service.

  2. The stubs and skeletons should implement all the remote interfaces that the server does, so that casting when you retrieve objects ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required