【问题标题】:RMI client with another port具有另一个端口的 RMI 客户端
【发布时间】:2014-01-29 07:17:17
【问题描述】:

我确实搜索了几个小时,但没有找到任何解决方案。我希望我在 VM(Windows server 2008)上的客户端与我的主机(主系统:windows 7)进行通信。

public class TestClient
{
    public static void main(String[] args) throws RemoteException, NotBoundException
    {
        Registry registry = LocateRegistry.getRegistry("13.211.124.80",TestRemote.RMI_PORT);
        TestRemote remote = (TestRemote) registry.lookup(TestRemote.RMI_ID);
        System.out.println(remote.isLoginValid("tst"));
        System.out.println(remote.isLoginValid("test"));
        System.out.println(TestRemote.RMI_PORT);
    }
}

来自主机的IP:13.211.124.80

RMI 服务器类

public class RMIServer
{
    public static void main (String[] args) throws RemoteException, AlreadyBoundException
    {
        RemoteImpl impl = new RemoteImpl();
        Registry registry=LocateRegistry.createRegistry(TestRemote.RMI_PORT);
        registry.bind(TestRemote.RMI_ID, impl);
        System.out.println("server is started");
    }
}

实现类:

public class RemoteImpl extends UnicastRemoteObject implements TestRemote
{
    private static final long serialVersionUID = 1L;    
    protected RemoteImpl() throws RemoteException
    {
        super();
        // TODO Auto-generated constructor stub 
    }

    public boolean isLoginValid(String username) throws RemoteException
    {
        if (username.equals("test"))
        {
            return true;
        }
        return false;
    }
}

接口类:

public interface TestRemote extends Remote
{
    public boolean isLoginValid(String username) throws RemoteException;
    public static final String RMI_ID = "TestRMI";
    public static final int RMI_PORT = 888;
}

错误:

线程“主”java.rmi.UnmarshalException 中的异常:解组返回错误;嵌套异常是: java.lang.ClassNotFoundException: com.interf.test.TestRemote(无安全管理器:RMI 类加载器已禁用)

【问题讨论】:

    标签: client-server port rmi


    【解决方案1】:

    异常非常清楚。无论哪个组件抛出该异常,其 CLASSPATH 中都没有该类。它可能是注册表或客户端,具体取决于您未完全发布的堆栈跟踪。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 2011-03-27
      • 2013-12-09
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多