2012-05-01 99 views
0

有誰可以幫助我使用ip建立rmi服務器。我一直在網上搜索幾天,但無法解決我的問題。帶有IP的RMI - ClassNotFoundException,UnmarshalException,ServerException

客戶

public static void main(String[] agrcs) throws RemoteException, NotBoundException, MalformedURLException { 
    if (System.getSecurityManager() == null) {  System.setProperty("java.security.policy", "F:\\škola\\pg2\\LodeSemestralka\\java.policy"); 

     System.setSecurityManager(new RMISecurityManager()); 
    } 
    String ip = agrcs[0]; 
    Integer port = new Integer(agrcs[1]); 

     server = (ShipServer) Naming.lookup("//"+ip+":"+port+"/"+SERVER_NAME); 
} 

服務器

static public void main(String[] agrcs) throws RemoteException { 
    if (System.getSecurityManager() == null) { 
     System.setProperty("java.security.policy", "F:\\škola\\pg2\\LodeSemestralka\\java.policy"); 
     System.setSecurityManager(new RMISecurityManager()); 
    } 

    String ip = agrcs[0]; 
    Integer port = new Integer(agrcs[1]); 

    playground = new Playground(); 
    try { 
     Naming.bind("//" + ip + ":" + port + "/" + SERVER_NAME, playground); 
    } catch (Exception ex) { 
     playground = null; 
     ex.printStackTrace(); 
    } 

當服務器被調用時,它拋出

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: lode.gameCore.Playground 
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:413) 
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267) 
    at sun.rmi.transport.Transport$1.run(Transport.java:177) 
    at sun.rmi.transport.Transport$1.run(Transport.java:174) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173) 
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273) 
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251) 
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377) 
    at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source) 
    at java.rmi.Naming.bind(Naming.java:128) 
    at server.Server.main(Server.java:38) 
    at lode.game.StartUpScreen.createNewGame(StartUpScreen.java:186) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662) 
    at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698) 
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) 
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) 
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289) 
    at java.awt.Component.processMouseEvent(Component.java:6504) 
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321) 
    at java.awt.Component.processEvent(Component.java:6269) 
    at java.awt.Container.processEvent(Container.java:2229) 
    at java.awt.Component.dispatchEventImpl(Component.java:4860) 
    at java.awt.Container.dispatchEventImpl(Container.java:2287) 
    at java.awt.Component.dispatchEvent(Component.java:4686) 
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) 
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) 
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) 
    at java.awt.Container.dispatchEventImpl(Container.java:2273) 
    at java.awt.Window.dispatchEventImpl(Window.java:2713) 
    at java.awt.Component.dispatchEvent(Component.java:4686) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707) 
    at java.awt.EventQueue.access$000(EventQueue.java:101) 
    at java.awt.EventQueue$3.run(EventQueue.java:666) 
    at java.awt.EventQueue$3.run(EventQueue.java:664) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) 
    at java.awt.EventQueue$4.run(EventQueue.java:680) 
    at java.awt.EventQueue$4.run(EventQueue.java:678) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:677) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) 
    at .... 

和lode.gameCore是public interface ShipServer extends Remote {...}public class Playground implements ShipServer, Serializable {...}

我使用的是LocaleRegistry,它可以很好地工作,但只能在一臺PC上運行。我需要通過網絡使用RMI與IP更多的PC上運行的應用,通信等

而且在java.policy文件是grant {permission java.security.AllPermission;};

回答

0
java.lang.ClassNotFoundException: lode.gameCore.Playground(Unknown Source) 
    ... 
    at java.rmi.Naming.bind(Naming.java:128) 

RMI註冊表不具有類的CLASSPATH 。註冊表需要遠程接口,存根(如果有的話)以及它們依賴的任何應用程序類,依此類推直到關閉。