/**
*java 文件
*/import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.util.Date;public class HelloServer extends UnicastRemoteObject implements HelloInterface{ public HelloServer() throws RemoteException{
super();// Call the superclass constructor to export this object
} public String sayHello() throws RemoteException{
return "Hello World, the current system time is " + new Date();
}
}import java.rmi.*;public class HelloClient { public static void main(String args[]) {
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
try {
HelloInterface obj = (HelloInterface) Naming.lookup("/HelloServer");
String message = obj.sayHello();
System.out.println(message);
} catch (Exception e) {
System.out.println("HelloClient exception: " +e);
}
}
}public interface HelloInterface extends java.rmi.Remote { // This method is called by remote clients and is implemented by the
// remote object
public String sayHello() throws java.rmi.RemoteException;
}
import java.rmi.*;public class RegisterIt { public static void main(String args[]) {
try {
// Instantiate the object
HelloServer obj = new HelloServer();
System.out.println("Object instantiated" +obj);
Naming.rebind ("/HelloServer", obj);
System.out.println("HelloServer bound in registry");
} catch (Exception e) {
System.out.println(e);
}
}
}/*
*registerit.policy
/*
grant {
// Allow everything for now
permission java.security.AllPermission;
};
*java 文件
*/import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.util.Date;public class HelloServer extends UnicastRemoteObject implements HelloInterface{ public HelloServer() throws RemoteException{
super();// Call the superclass constructor to export this object
} public String sayHello() throws RemoteException{
return "Hello World, the current system time is " + new Date();
}
}import java.rmi.*;public class HelloClient { public static void main(String args[]) {
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
try {
HelloInterface obj = (HelloInterface) Naming.lookup("/HelloServer");
String message = obj.sayHello();
System.out.println(message);
} catch (Exception e) {
System.out.println("HelloClient exception: " +e);
}
}
}public interface HelloInterface extends java.rmi.Remote { // This method is called by remote clients and is implemented by the
// remote object
public String sayHello() throws java.rmi.RemoteException;
}
import java.rmi.*;public class RegisterIt { public static void main(String args[]) {
try {
// Instantiate the object
HelloServer obj = new HelloServer();
System.out.println("Object instantiated" +obj);
Naming.rebind ("/HelloServer", obj);
System.out.println("HelloServer bound in registry");
} catch (Exception e) {
System.out.println(e);
}
}
}/*
*registerit.policy
/*
grant {
// Allow everything for now
permission java.security.AllPermission;
};
*把几个.java文件删掉,只保留.class,再运行试试
/*error: Class HelloServer not found.
second , you java files name is exactly same to the your class name .
now ,try ! any question ,please write to [email protected] , I would like to
support some Java friends!