Java RMI ServerException - java.lang.ClassNotFoundException: org.prog.rmi.RmiServer_Stub

发布于 2024-12-01 08:21:38 字数 3720 浏览 0 评论 0原文

我继承了一些 Java RMI 客户端/服务器代码,虽然它在一台机器上运行良好,但我无法让它在我的开发环境中运行。

问题是当我使用以下 java.exe -Djava.security.policy=conf\server.policy -SRC; 运行服务器时。 -Djava.library.path=. org.prog.rmi.RmiServer

我收到以下错误:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: org.prog.rmi.RmiServer_Stub (no security manager: RMI class loader disabled)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
    at sun.rmi.transport.Transport$1.run(Transport.java:159)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
    ...

我的 server.policy 文件是

grant {
    permission java.security.AllPermission;
};

我的 java 代码:

        package org.prog.rmi;

        import java.rmi.Naming;
        import java.rmi.RemoteException;
        import java.rmi.RMISecurityManager;
        import java.rmi.server.UnicastRemoteObject;
        import java.rmi.registry.*; 

        public class RmiServer extends UnicastRemoteObject 
            implements RmiServerIntf {

        private BatchApi bapi;
        private String iniFileLocation;
        private String layoutOption;
        private int addressCount = 0;
        private RefInt apiHandle = new RefInt();


        public RmiServer(String iniFileLocation,String layoutOption) throws RemoteException 
        {   super();
            this.iniFileLocation = iniFileLocation;
            this.layoutOption = layoutOption;
            initAPI();
            startupAPI();
            openAPI();      
        }

        public static void main(String args[]) 
        {
            System.out.println("RMI server started");

            // Create and install a security manager
            if (System.getSecurityManager() == null) 
            {
                System.setSecurityManager(new RMISecurityManager());
                System.out.println("Security manager installed.");
            }
            else
                System.out.println("Security manager already exists.");

            try  //special exception handler for registry creation
            {
                LocateRegistry.createRegistry(1099); 
                System.out.println("java RMI registry created.");
            }
            catch (RemoteException e)
            {
                //do nothing, error means registry already exists
                System.out.println("java RMI registry already exists.");
            }

            try
            {
                //Instantiate RmiServer
                for (String arg: args){
                    System.out.println(arg);
                }

                RmiServer obj = new RmiServer(args[0],args[1]);

                // Bind this object instance to the name "RmiServer"
                Naming.rebind("//127.0.0.1/RmiServer", obj);
                System.out.println("PeerServer bound in registry");

            } 
            catch (Exception e) 
            {
                System.err.println("RMI server exception:");
                e.printStackTrace();
            }
        }    
}

我已经看到了与 java.rmi 相关的解决方案。 server.codebase 但也没有任何运气设置这个

I have inherited some Java RMI client/server code, and while it runs fine on one machine, I haven't been able to get it to run in my dev environment.

The problem is when I run the server using the following java.exe -Djava.security.policy=conf\server.policy -SRC;. -Djava.library.path=. org.prog.rmi.RmiServer

I get the following error:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: org.prog.rmi.RmiServer_Stub (no security manager: RMI class loader disabled)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
    at sun.rmi.transport.Transport$1.run(Transport.java:159)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
    ...

My server.policy file is

grant {
    permission java.security.AllPermission;
};

And my java code:

        package org.prog.rmi;

        import java.rmi.Naming;
        import java.rmi.RemoteException;
        import java.rmi.RMISecurityManager;
        import java.rmi.server.UnicastRemoteObject;
        import java.rmi.registry.*; 

        public class RmiServer extends UnicastRemoteObject 
            implements RmiServerIntf {

        private BatchApi bapi;
        private String iniFileLocation;
        private String layoutOption;
        private int addressCount = 0;
        private RefInt apiHandle = new RefInt();


        public RmiServer(String iniFileLocation,String layoutOption) throws RemoteException 
        {   super();
            this.iniFileLocation = iniFileLocation;
            this.layoutOption = layoutOption;
            initAPI();
            startupAPI();
            openAPI();      
        }

        public static void main(String args[]) 
        {
            System.out.println("RMI server started");

            // Create and install a security manager
            if (System.getSecurityManager() == null) 
            {
                System.setSecurityManager(new RMISecurityManager());
                System.out.println("Security manager installed.");
            }
            else
                System.out.println("Security manager already exists.");

            try  //special exception handler for registry creation
            {
                LocateRegistry.createRegistry(1099); 
                System.out.println("java RMI registry created.");
            }
            catch (RemoteException e)
            {
                //do nothing, error means registry already exists
                System.out.println("java RMI registry already exists.");
            }

            try
            {
                //Instantiate RmiServer
                for (String arg: args){
                    System.out.println(arg);
                }

                RmiServer obj = new RmiServer(args[0],args[1]);

                // Bind this object instance to the name "RmiServer"
                Naming.rebind("//127.0.0.1/RmiServer", obj);
                System.out.println("PeerServer bound in registry");

            } 
            catch (Exception e) 
            {
                System.err.println("RMI server exception:");
                e.printStackTrace();
            }
        }    
}

I've seen solutions relating to the java.rmi.server.codebase but didn't have any luck setting this either

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半衬遮猫 2024-12-08 08:21:38

您尚未使用rmic重新生成存根,或者注册表无法通过其类路径访问它。

You haven't regenerated the stub with rmic, or the Registry doesn't have access to it via its classpath.

酒废 2024-12-08 08:21:38

经过进一步调查并遵循 RMI 教程后,发现端口 1099 上的 RMI 注册服务器出现问题。

当我在另一个端口(例如 2005)上启动 RMI 注册服务器并更改这些代码

LocateRegistry.createRegistry(2005);

行时,

Naming.rebind("//127.0.0.1:2055/RmiServer", obj);

它成功运行,没有错误我的客户能够连接。

我希望这个答案可以帮助其他人解决这个错误。如果有人需要更多详细信息,请告诉我。

After some further investigation and following RMI tutorials it appeared that there was a problem with the RMI registration server on port 1099.

When I stared the RMI registration server on another port (e.g. 2005) and changed these lines of code

LocateRegistry.createRegistry(2005);

and

Naming.rebind("//127.0.0.1:2055/RmiServer", obj);

This ran sucessfully without errors and my client was able to connect.

I hope this answer helps others with this error. Let me know if anyone needs any more detailed information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文