【问题标题】:running java rmi server运行 java rmi 服务器
【发布时间】:2015-07-04 23:43:43
【问题描述】:

我正在使用 RMI 技术创建一个项目,它可以按我的意愿运行,但现在我想将我的 RMI 类上传到服务器,我应该如何以及如何做?

我尝试过这样做:

public static void main (String [] arg) {
    try {
        LocateRegistry.createRegistry(30);
        Registry reg = LocateRegistry.getRegistry("127.0.0.1",30);
        ImbCal  c = new ImbCal();

        reg.rebind("MSA", c);
        reg.rebind("Work", c);

        System.out.println("Server is ready ....");

        System.in.read();


    }catch(Exception ex){
      ex.printStackTrace();
      System.out.print(ex.getMessage());
    }
}

我知道应该:

  1. 更改本地主机地址。
  2. 为 ear 或 war 等服务器创建部署 jar。

我已经创建了一个接口和一个客户端类,并在本地测试了我的项目,它运行良好。

【问题讨论】:

  • “将我的 RMI 类上传到服务器”是什么意思?
  • 我的意思是“将我的 RMI 类上传到服务器”,我想通过服务器而不是本地运行它。另外,我想知道如何创建部署 jar。谢谢

标签: java server rmi


【解决方案1】:

我尝试了很多,直到我解决它,我只需要在服务器类中创建注册表,而在客户端类中我应该通过服务器类的地址获取注册表

服务器类:

try {
    /*here create the registry*/
    Registry reg = LocateRegistry.createRegistry(30);
    ImbCal  c = new ImbCal();
    reg.rebind("MSA", c);
    reg.rebind("Work", c);
    System.out.println("Server is ready ....");
    System.in.read();
}catch(Exception ex){
  ex.printStackTrace();
  System.out.print(ex.getMessage());
}

客户端类:

        try {               
            Registry myReg = LocateRegistry.getRegistry("192.168.1.5",30);      
            System.out.println("running...");
            CalInterface c= (CalInterface)myReg.lookup("MSA");      
             WorkInterface w= (WorkInterface)myReg.lookup("Work");  
        } catch (Exception e) {
            e.printStackTrace();

        }

}

【讨论】:

  • 这与“上传[ing]我的 RMI 类到服务器”有什么关系?
猜你喜欢
  • 1970-01-01
  • 2016-01-11
  • 2010-10-02
  • 1970-01-01
  • 2016-11-06
  • 1970-01-01
  • 1970-01-01
  • 2013-01-28
相关资源
最近更新 更多