i like to call RMI,but the Exception is throwed.what's wrong with it?
Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is: java.lang.ClassNotFoundException: test.Hello (no security manager: RMI class loader disabled) at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source) at java.rmi.Naming.lookup(Unknown Source) at com.xx.rmiproxy.RmiProxy.call(RmiProxy.java:39) at com.xx.rmiproxy.RmiProxy.main(RmiProxy.java:18) Caused by: java.lang.ClassNotFoundException: test.Hello (no security manager: RMI class loader disabled) at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source) at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
public String call(String rmiId, String json) throws Exception{
RmiInterfaceDescription desc = dao.getDescriptionById(rmiId);
desc.setJarFile("d:\\test.jar");
RmiClientClassLoader rmiClassLoader = new RmiClientClassLoader(null,desc);
Class interfaceClass = rmiClassLoader.loadClass(desc.getInterfaceName());
List<String> paraClasses = desc.getParaClasses();
Class returnClass = rmiClassLoader.loadClass(desc.getReturnClass());
Object obj = Naming.lookup(desc.getRmiUrl());
Class[] parameterTypes = new Class[paraClasses.size()];
for(int i=0;i<paraClasses.size();i++){
parameterTypes[i]= rmiClassLoader.loadClass(paraClasses.get(i));
}
Method method = interfaceClass.getDeclaredMethod(desc.getMethodName(),
parameterTypes);
Object params[] = parseParamsFromJson();
Object result = method.invoke(obj, "ssd");
return encode(result);
}
.....
public class RmiClientClassLoader extends URLClassLoader {
public static void main(String args[]) throws Exception {
RmiInterfaceDescription description = new RmiInterfaceDescription();
description.setJarFile("d:\\test.jar");
RmiClientClassLoader cl = new RmiClientClassLoader(null, description);
Class clientClass = cl.loadClass("test.client.HelloClient");
}
private String basedir;
private RmiInterfaceDescription description;
@SuppressWarnings("deprecation")
public RmiClientClassLoader(String basedir,
RmiInterfaceDescription description) throws MalformedURLException {
super(new URL[] { new File(description.getJarFile()).toURL() });
this.basedir = basedir;
this.description = description;
}