Java RMI服务器问题

时间:2016-07-04 16:32:40

标签: java eclipse rmi

我提前道歉可能是一个明显的问题,但我一直试图让这一整天工作,我无法弄清楚如何让它发挥作用。简而言之:我的RMIregistry无法找到我的RMI服务器应用程序的接口类。

我通过Eclipse使用以下参数运行rmiregistry.exe:

1234 -J-Djava.rmi.server.useCodebaseOnly=false

我得到了以下RMI服务器:

        package es.test.innova.pruebas.test;

    import java.io.File;
    import java.rmi.Naming;
    import java.rmi.RMISecurityManager;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;

    public class TestImpl extends UnicastRemoteObject implements Test
    {
        public TestImpl() throws RemoteException {}

        public static void main(String args[])
        {
            try
            {           
             if (System.getSecurityManager() == null) {
                 System.setSecurityManager(new RMISecurityManager());
                 } 

                TestImpl obj = new TestImpl();

                Naming.rebind("rmi://localhost:1234/Test",obj);
                System.out.println("Connected to registry!");
            }
            catch (Exception e)
            {
                System.out.println("HelloImpl err: " + e.getMessage());
                e.printStackTrace();
            }
        }

        @Override
        public String validate(File f) throws RemoteException {
            return "hello world";
        }
}

然后我使用这些参数运行:

-Djava.security.policy=C:\D\RMI\policy.all -Djava.rmi.server.codebase=file:/C:/D/Proyectos/Firma/validarfirma/

引用的政策文件是:

grant {
    permission java.security.AllPermission "", "";
};

codebase参数引用了项目的文件夹,我还尝试将其指向文件夹的bin文件夹,甚至直接指向.class文件,如本文其他答案中所述。站点。

无论我尝试什么,我都会收到此错误:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: es.test.innova.pruebas.test.Test
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
    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:556)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at java.rmi.Naming.rebind(Naming.java:177)
    at es.test.innova.pruebas.test.TestImpl.main(TestImpl.java:25)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: es.test.innova.pruebas.test.Test
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
    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:556)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException: es.test.innova.pruebas.test.Test
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1206)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1219)
    at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:729)
    at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:673)
    at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:610)
    at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646)
    at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311)
    at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:255)
    at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1556)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1512)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
    ... 13 more
HelloImpl err: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: es.test.innova.pruebas.test.Test

未找到班级。我已尝试手动运行所有内容而不是使用Eclipse,直接从.class文件夹运行rmi,将服务器编译为.jar并使用它代替......当然,我已经摆弄了代码库参数一堆。我已经尝试了所有我能想到的东西,但我已经陷入困境。

问题是我必须设置错误的代码库或者像那样,但我不知道如何。注册表无法找到我的课程。

如果有人能帮助我,我将非常感激。谢谢你的阅读。

1 个答案:

答案 0 :(得分:0)

-Djava.rmi.server.codebase=file:/C:/D/Proyectos/Firma/validarfirma/

这意味着缺少的类应该位于:

C:/D/Proyectos/Firma/validarfirma/es/test/innova/pruebas/test/Test.class