【发布时间】: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