线程“main”中的异常java.rmi.ServerException:服务器线程中发生了RemoteException

时间:2016-10-07 10:24:13

标签: java rmi

我试图在eclipse中实现一个简单的RMI添加服务器,但是我得到了一个解组异常。那我错过了什么?我是否必须生成存根文件?在下面找到我的代码。

//The Interface
package test_rmi;

public interface sumInterface extends java.rmi.Remote
{
    int find_sum(int n1,int n2) throws java.rmi.RemoteException;
}


//The Implementation
package test_rmi;

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class sumImpl extends UnicastRemoteObject implements sumInterface{

private static final long serialVersionUID = 1L;

protected sumImpl() throws RemoteException {
    super();
        // TODO Auto-generated constructor stub
    }

        public int find_sum(int n1,int n2) throws RemoteException
        {
            int ans=0;
            ans = n1+n2;
            return ans;
        }

}


//The Server
package test_rmi;
import java.net.MalformedURLException;
import java.rmi.*;
import java.rmi.registry.*;

public class sumServer
{
    public static void main(String args[]) throws RemoteException, AlreadyBoundException, MalformedURLException{

        sumImpl abc = new sumImpl();
        Naming.rebind("SUM", abc);
    }
}

//The Client
package test_rmi;

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.util.Scanner;
import java.io.DataInputStream;

public class sumClient
{
    public static void main(String args[])
    {


        try
        {
            int ans;
            System.out.println("HOWDY");
            sumInterface pi = (sumInterface) Naming.lookup("BOOBOO");
            System.out.println("FOUND!!");

            System.out.print("Enter Number 1 : ");
            Scanner sc = new Scanner(System.in);
            String int1 = sc.nextLine();

            System.out.print("Enter Number 2 : ");
            Scanner sc1 = new Scanner(System.in);
            String int2 = sc.nextLine();

            ans = pi.find_sum((Integer.parseInt(int1)),Integer.parseInt(int2));
            System.out.println(ans);
        }
        catch(Exception e) { }
    }
} 

RMI注册表在默认端口1099上处于活动状态,但获得以下解组异常:

Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: test_rmi.sumInterface
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:421)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:272)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:177)
at test_rmi.sumServer.main(sumServer.java:12)
    Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:java.lang.ClassNotFoundException: test_rmi.sumInterface
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:411)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:272)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
       Caused by: java.lang.ClassNotFoundException: test_rmi.sumInterface
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1221)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:731)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:674)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:611)
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:265)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1566)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1781)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
... 15 more

0 个答案:

没有答案