0

有谁可以帮助我使用 ip 建立 rmi 服务器。我已经在网上搜索了几天,但无法解决我的问题。

客户

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 上运行。我需要通过网络使用带有 IP 的 RMI 在更多 PC 上运行应用程序,以进行通信等。

在 java.policy 中是grant {permission java.security.AllPermission;};

4

1 回答 1

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

RMI 注册表在其 CLASSPATH 中没有该类。Registry 需要远程接口、存根(如果有)以及它们所依赖的任何应用程序类,依此类推,直到关闭。

于 2012-05-02T04:09:33.213 回答