Linux RMI Simple Example Analysis

Source: Internet
Author: User

I found a simple RMI example on the Internet. I didn't expect it to be a simple example. I encountered many problems. I will analyze these problems and solutions for your reference.

Post Code first

Remote interface helloin. Java
Import java. RMI .*;
Public interface helloin extends java. RMI. Remote {
String sayhello () throws RemoteException;
}

Hello. Java

Import java. RMI .*;
Import java.net .*;
Import java. RMI. Registry .*;
Import java. RMI. server .*;
Public class Hello extends java. RMI. server. unicastremoteobject implements helloin {
Public Hello () throws RemoteException {
Super ();
}
Public String sayhello () throws RemoteException {
Return "Hello, world! ";
}
Public static void main (string [] ARGs) {// Service Registration
Try {
Hello H = new Hello ();
Java. RMI. Naming. rebind ("hello", H );
System. Out. Print ("ready ......");
}
Catch (exception e ){
E. printstacktrace ();
}
}
}

Client Program helloworld. Java

Import java. RMI .*;
Import java. RMI. Registry .*;
Public class helloworld {
Public static void main (string [] ARGs ){
Try {
Helloin HI = (helloin) Naming. Lookup ("hello ");
For (INT I = 0; I <10; I ++ ){
System. Out. println (Hi. sayhello ());
}
}
Catch (exception e ){
E. printstacktrace ();
}
}
}

OK. The three code files have been written, and then perform the following steps:

1. Switch to the directory where the three code files are located on the terminal

1.1 compile and generate helloin. Class

1.2 compile and generate hello. Class (to be converted into helloin. class, because there is dependency (compiling command javac-CP xxxxxx hello. Java) xxxxxx is helloin. ClassDirectory)

2. rmic Hello generates hello_stub.class (One method is to switch to JDK/bin and run rmic directly, and the other method is to add the hello. Class file directory to classpath)

3. Run hello. Java in eclipse

4. Run rmiregistry (switch to JDK/bin)

5. Run helloworld. Java again.

Some documents mentioned that the skeleton. Class file will be generated, which should also be in theory. However, I did not generate this file according to the steps they mentioned, but the running results are also normal. Which of the following can be explained?

The above method has integrated the error solution and the code has been run.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.