0
服務器:RMI客戶com.sun.proxy.Proxy無法施展錯誤
package server;
import java.rmi.*;
public interface iCSServer extends Remote
{
public int Findnumber(int num) throws RemoteException;
}
package server;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
而且
public class CSServer extends UnicastRemoteObject implements iCSServer {
private static final long serialVersionUID = 01; // version 01
int N=1000; // number of ids
int[] Ids=new int[N]; // data structure for storing the Ids
public CSServer() throws RemoteException
{
}
public void Add_Ids() // add ids to data
{
for(int i=0;i<N;i++)
{
Ids[i]=i+ (i+1)*10;
}
}
public int Findnumber(int num) throws RemoteException
{
for(int i=0;i<N;i++)
{
if(num==Ids[i])
{
return i;
}
}
return -1;
}
public static void main(String[] args) throws RemoteException {
System.setProperty("java.rmi.server.hostname","127.0.0.1");
LocateRegistry.createRegistry(1099);
// System.out.println(LocateRegistry.getRegistry(1099).toString());
CSServer obj=new CSServer();
obj.Add_Ids();
try {
Naming.rebind ("CSServer", obj);
System.out.println ("CS218 Server is running.");
}
catch (Exception e) {
System.out.println ("CS218 server cannot run: " + e);
}
}
}
服務器啓動並運行良好。
客戶:
package client;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.*;
public interface iCSServer extends Remote
{
public int Findnumber(int num) throws RemoteException;
}
而且
package client;
import java.rmi.Naming;
import java.rmi.registry.*;
public class clientApp {
public static void main(String[] args)
{
try{
iCSServer obj = (iCSServer) Naming.lookup("//localhost:1099/CSServer");
//Registry registry = LocateRegistry.getRegistry("127.0.0.1");
//iCSServer obj=(iCSServer) registry.lookup("CSServer");
System.out.println("pass");
System.out.println(obj.Findnumber(100));
}
catch(Exception ex)
{
System.out.println("fail");
System.out.println(ex.getMessage());
}
}
}
然而,當我運行客戶端我得到這個錯誤:
fail
error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: server.iCSServer (no security manager: RMI class loader disabled)
然後我添加的服務器的jar'd版本.ICSServer,我相信解決這個問題。然而,我再次運行它,現在我得到這個錯誤:
fail
com.sun.proxy.$Proxy0 cannot be cast to client.iCSServer
任何想法如何解決?