RMI调用中,网上多数使用stub,害的我搞了一天,
其实可以用代码实现。
客户端与服务器的代码及接口不写了,反正就是实现remote继承什么。
现在贴出来RMI Server的代码。如何注册服务
try {
URL pathURL = RmiServer.class.getResource("");
String pathToCodebase = pathURL.toString();
pathToCodebase = pathToCodebase.replace(" ", "%20");
System.setProperty("java.rmi.server.codebase", pathToCodebase);
LocateRegistry.createRegistry(1099);
NumberStateQueryImpl localObject = new NumberStateQueryImpl(); //生成远程对象实现的一个实例
Naming.rebind("rmi://"+server+":1099/avaya", localObject); //将远程对象实例绑定到rmi:///Rem上
System.out.println("RMI Start....");
}catch(RemoteException re){
System.out.println("RemoteException:"+re);
}catch(Exception mfe) {
System.out.println("MalformedURLException: "+mfe);
}
如果没有授权,加上
System.setSecurityManager(new RMISecurityManager());
。搞了好久,郁闷。
网上信息多误导。
其实可以用代码实现。
客户端与服务器的代码及接口不写了,反正就是实现remote继承什么。
现在贴出来RMI Server的代码。如何注册服务
try {
URL pathURL = RmiServer.class.getResource("");
String pathToCodebase = pathURL.toString();
pathToCodebase = pathToCodebase.replace(" ", "%20");
System.setProperty("java.rmi.server.codebase", pathToCodebase);
LocateRegistry.createRegistry(1099);
NumberStateQueryImpl localObject = new NumberStateQueryImpl(); //生成远程对象实现的一个实例
Naming.rebind("rmi://"+server+":1099/avaya", localObject); //将远程对象实例绑定到rmi:///Rem上
System.out.println("RMI Start....");
}catch(RemoteException re){
System.out.println("RemoteException:"+re);
}catch(Exception mfe) {
System.out.println("MalformedURLException: "+mfe);
}
如果没有授权,加上
System.setSecurityManager(new RMISecurityManager());
。搞了好久,郁闷。
网上信息多误导。