设置简单 RMI 服务器时出现问题

发布于 2024-11-17 10:07:51 字数 5443 浏览 1 评论 0 原文

我在设置简单的 RMI 服务器时遇到问题,想知道是否有人可以为我指明正确的方向。

我有一个简单的类 Server,它应该导出一个简单的接口。目前,当我尝试运行服务器类时,出现以下异常:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: prototype.ISimpleService

我已经通过运行“start rmiregistry”命令确保 rmi 注册表正在运行,并且我正在使用以下参数运行服务

-Djava.rmi.server.codebase=file:C:/Users/John/Documents/NetBeansProjects/Prototype/build/classes

中的路径上面的参数指向我的类层次结构的顶级文件夹,因此:

/classes

/prototype

->ISimpleService.class

->SimpleServiceImpl.class

->IServer.class

这是我的服务器代码:

public class Server
{
    private static ISimpleService service;

    public static void main(String[] args)
    {
        service = new SimpleServiceImpl();

        try
        {
            ISimpleService stub = (ISimpleService) UnicastRemoteObject.exportObject(service, 0);

            Registry registry = LocateRegistry.getRegistry();

            registry.rebind("SimpleService", stub);

            System.out.println("Simple Service bound");
        } 
        catch (Exception ex)
        {
            System.out.println("Exception binding the simple service");
            ex.printStackTrace();
        }
    }
}

我看过在Java RMI跟踪中,并调整了我的简单示例来遵循这一点,尽管我没有使用我不需要的安全/权限,因为我之前已经得到了一个在没有这些东西的情况下工作的RMI示例......

所以我相信我必须缺少一些简单的东西(没有双关语的意思),使这项工作正常进行,但我现在看不到任何东西。

有人有想法吗?

这是完整的堆栈跟踪:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: prototype.ISimpleService
    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)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask    (ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer    (StreamRemoteCall.java:255)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at prototype.Server.main(Server.java:35)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: prototype.ISimpleService
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386)
    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)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask    (ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: prototype.ISimpleService
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:711)
    at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:655)
    at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:592)
    at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628)
    at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294)
    at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238)
    at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1530)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1492)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    ... 12 more

I am having a problem setting up a simple RMI server, and was wondering if someone can point me in the right direction.

I have a simple class, Server, that should export an simple interface. Currently when I try and run the server class, I get the following exception:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: prototype.ISimpleService

I have already made sure that the rmi registry is running, by running the "start rmiregistry" command, and I am running the service with the following argument

-Djava.rmi.server.codebase=file:C:/Users/John/Documents/NetBeansProjects/Prototype/build/classes

The path in the argument above points to the top level folder of my class hierarchy, so:

/classes

/prototype

->ISimpleService.class

->SimpleServiceImpl.class

->IServer.class

Here is my server code:

public class Server
{
    private static ISimpleService service;

    public static void main(String[] args)
    {
        service = new SimpleServiceImpl();

        try
        {
            ISimpleService stub = (ISimpleService) UnicastRemoteObject.exportObject(service, 0);

            Registry registry = LocateRegistry.getRegistry();

            registry.rebind("SimpleService", stub);

            System.out.println("Simple Service bound");
        } 
        catch (Exception ex)
        {
            System.out.println("Exception binding the simple service");
            ex.printStackTrace();
        }
    }
}

I have looked at the Java RMI trail, and adapted my simple example to follow that, although I am not using security/permissions that I shouldn't need as I have gotten an RMI example working before without that stuff...

So I believe I have to missing something simple(no pun intended), to make this work, but I cant see anything at the moment.

Do anyone have an ideas?

Here is the full stack trace:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: prototype.ISimpleService
    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)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask    (ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer    (StreamRemoteCall.java:255)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at prototype.Server.main(Server.java:35)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: prototype.ISimpleService
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386)
    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)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask    (ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: prototype.ISimpleService
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:711)
    at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:655)
    at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:592)
    at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628)
    at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294)
    at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238)
    at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1530)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1492)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    ... 12 more

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

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

发布评论

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

评论(2

卷耳 2024-11-24 10:07:51

我已经解决了这个问题...虽然比我预期的要长一点:(

结果是当你像我一样使用代码库参数时,如果你指向一个目录,你应该在末尾放置一个尾随“/”添加后,我的服务器成功绑定。

有关此 p 上的资源,请参阅 http://download.oracle.com/javase/1.4.2/docs/guide/rmi/codebase.html#section6

I have solved this issue... Took me alittle longer than I expected though :(

Turns out when you use a codebase argument like I had done, you should place a trailing "/" at the end, if you are pointing to a directory. Once I added that in, my server successfully binds.

For a resource on this p see http://download.oracle.com/javase/1.4.2/docs/guide/rmi/codebase.html#section6

桜花祭 2024-11-24 10:07:51

看来 prototype.ISimpleService 不在您的类路径中。

尝试:

java -cp=C:/Users/John/Documents/NetBeansProjects/Prototype/build/classes;C:/Users/John/Documents/NetBeansProjects/Server/build/classes Server

It seems prototype.ISimpleService is not in your classpath.

Try:

java -cp=C:/Users/John/Documents/NetBeansProjects/Prototype/build/classes;C:/Users/John/Documents/NetBeansProjects/Server/build/classes Server
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文