1.2.3 定义服务端程序入口
public class PersonalServer { //------------------------------------------------------------------------- public static void main(String [] args) throws RemoteException, MalformedURLException { PersonalServer server = new PersonalServer(); } //------------------------------------------------------------------------- public PersonalServer() throws RemoteException, MalformedURLException { PersonalImpl p1 = new PersonalImpl(); //Bind remote object with name Naming.rebind("Personal.Information.Server", p1); }
1.2.4 执行rmic工具生成存根类
1.2.5 启动RMI注册表工具(rmiregistry)
1.2.6 执行服务端入口类
1.2.7 检查远程对象注册
该步骤主要为了检查RMI服务端是否启动正常。以下是检查注册用代码:
public class CheckBinds { //------------------------------------------------------------------------- public static void main(String [] args) throws Exception { CheckBinds checher = new CheckBinds(); } //------------------------------------------------------------------------- public CheckBinds() throws Exception { try { String [] bindsList = Naming.list(""); //List all binds for(int i = 0; i < bindsList.length; ++i) { System.out.println(bindsList[i]); }
检查程序应该输出://:1099/Personal.Information.Server才说明远程对象绑定正常。