在同一台电脑上运行通过,从另一台电脑运行客户端时出现问题!
客户端:
public class ExecuteEcho {
public static void main(String args[]) {
//System.setProperty(“java.rmi.server.codebase”,”http://192.168.1.154/E:/eclipse/workspace/rmi”);
/*
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
} */
try {
String name = “//” + args[0] + “/Compute”;
Compute comp = (Compute) Naming.lookup(name);
System.out.println(“please input the string to echoed”);
Echo toEcho = new Echo(Input.readString());
//comp.executeTask(toEcho);
System.out.println(comp.executeTask(toEcho));
} catch (Exception e) {
System.err.println(“Compute exception: ” +
e.getMessage());
e.printStackTrace();
}
}
}
服务器端:
public static void main(String[] args) {
/*System.setProperty(“java.rmi.server.codebase”,”http://localhost/RMIServer/”);
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}*/
String name = “//localhost/Compute”;
try {
Compute engine = new ComputeEngine();
Naming.rebind(name, engine);
System.out.println(“ComputeEngine bound”);
} catch (Exception e) {
System.err.println(“ComputeEngine exception: ” + e.getMessage());
e.printStackTrace();
}
}
异常:
Compute exception: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: RMIServer.ComputeEngine_Stub (no security manager: RMI class loader disabled)
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: RMIServer.ComputeEngine_Stub (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at RMIClient.ExecuteEcho.main(ExecuteEcho.java:16)
Caused by: java.lang.ClassNotFoundException: RMIServer.ComputeEngine_Stub (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:371)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1543)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1465)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1698)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
… 3 more