我有以下情況:java.rmi.UnmarshalException:錯誤解組返回;嵌套的異常是:java.lang.ClassNotFoundException:
使用RMI,我注意到在特定情況下,RMI客戶端沒有實例通過RMI發送的類。所以,我以Byte []的形式發送了類,然後用我定義的類加載器加載它。
在客戶端的代碼是一樣的東西:
HashMap<String, PluginPanel> panels = null;
try
{
panels = plugins.getSettingsPanels();
} catch (RemoteException ex)
{
Logger.getLogger(ServerOptions.class.getName()).log(Level.SEVERE, null, ex);
}
PluginPanel是一個接口,其實現:
pp = plugins.getPanelClasses(); //RMI method
panelClassLoader pcl = new panelClassLoader(); //simple class loader defined by me
String name = pcl.defineClass(pp);
然後,我在客戶端通過類的加載實例問類並不總是在客戶端...
和類加載器是:
private class panelClassLoader extends ClassLoader
{
public panelClassLoader(ClassLoader parent)
{
super(parent);
}
public panelClassLoader()
{
super(getSystemClassLoader());
}
public String defineClass(byte[] b)
{
Class c = super.defineClass(null, b, 0, b.length);
resolveClass(c);
return c.getName();
}
}
不過,我遇到以下錯誤: java.rmi.UnmarshalException:error unmarshalling return;嵌套異常是: java.lang.ClassNotFoundException:pt.ua.dicoogle.IndexPlugin.CPanel(沒有安全管理器:禁用RMI類加載器) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:178) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178) 在java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132) 在$ Proxy22.getSettingsPanels(來源不明) 在pt.ua. dicoogle.rGUI.client.windows.ServerOptions(ServerOptions.java:176)
造成的:拋出java.lang.ClassNotFoundException:pt.ua.dicoogle.IndexPlugin.CPanel(無安全管理器:RMI類加載器禁用) at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:375) 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:1574) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731) at java.io.ObjectInputStream.readObject0(ObjectInputStream .java:1328) at java.io.ObjectInputStream.readObject (ObjectInputStream.java:350) 在java.util.HashMap.readObject(HashMap.java:1030) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 39) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) 在java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java: 974) 在java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848) 在java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) 在java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) a t java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef。java:306) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:155)
任何消??