RMI的问题,怎么没人回答那??

btcrazyfan 2004-03-27 09:36:36
E:\>java javarmi.ClockServer
java.rmi.ServerException: Server RemoteException; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is:
java.lang.ClassNotFoundException: javarmi.ClockImpl_Stub
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
n Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at javarmi.ClockServer.<init>(ClockServer.java:14)
at javarmi.ClockServer.main(ClockServer.java:23)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested ex
ception is:
java.lang.ClassNotFoundException: javarmi.ClockImpl_Stub
Caused by: java.lang.ClassNotFoundException: javarmi.ClockImpl_Stub

我已经用相应的方法声称了ClockImpl_Stub.class,可是仍然提示有问题,如何是好???
所用方法: rmic -v1.2 javarmi.ClockImpl
...全文
84 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnham 2004-08-23
  • 打赏
  • 举报
回复
mark!
sandsworlf 2004-07-05
  • 打赏
  • 举报
回复
我觉得XML-RPC比较好用,是轻量级的rmi,
看看api一般就知道怎么调用了
http://www.xmlrpc.com/
里面有例子的
gonewithgirl 2004-07-05
  • 打赏
  • 举报
回复
你调用start rmiregistry时注册与对应名字对应的对象到命名服务器时,不能关闭弹出的窗口。
你照着下面的步骤试试:
下面是清华大学视频教材的一个例子:
 1. 构造一个远程接口Hello:

  package hello;
  public interface Hello extends java.rmi.Remote {
  //rmi应用程序必须继承自java.rmi.Remote
    String sayHello() throws java.rmi.RemoteException ;
    //定义可以远程调用的接口
  }

 2. 完成server方程序,定义HelloImpl类实现Hello接口:

  package hello;
  import java.rmi.*;
  import java.rmi.server.UnicastRemoteObject;
  public class HelloImpl extends UnicastRemoteObject implements Hello
                     //实现Hello接口
  {
    private String name;
    public HelloImpl (String s ) throws java.rmi.RemoteException{
    super(); //调用父类的构造函数
    name = s;
  }
  public String sayHello() throws RemoteException {
    return "Hello world!"; //实现Hello接口定义的方法
  }
  public static void main ( String args [])
  {
    System.setSecurityManager ( new RMISecurityManager() );
    //设置RMI程序需要的安全策略
    try
    {
     HelloImpl obj = new HelloImpl("HelloServer");
     //生成一个HelloImpl的实例
     Naming.rebind("HelloServer", obj);
     //将这个实例绑定到一个名字上
     System.out.println("HelloImpl created and bound in the registry to the name HelloServer");
    } catch (Exception e)
    {
     System.out.println("HelloImpl.main: an exception occured:");
     e.printStackTrace(); //产生异常的话,打印出出错信息
    }
  }
}

  server方生成一个远程对象并和一个可和客户对话的名称"HelloServer"绑定。Client端可以根据该名称寻找相应的远程对象,进而调用其远程方法。

 3. 完成client方程序

  package hello;
  import java.rmi.*; public class HelloClient
  {
   public static void main(String args[])
  {
   System.setSecurityManager(new RMISecurityManager() );
   //设置RMI需要的安全策略
   try
   {
    Hello obj = (Hello) Naming.lookup("HelloServer");
    //从服务端获得一个Hello的远程对象
    String message = obj.sayHello();
    //远程调用Hello的方法
    System.out.println(message);
    //将输出结果打印
   } catch (Exception e)
   {
    System.out.println("Hello client : an exception occured");
    e.printStackTrace(); //若有异常,输出异常信息
   }
  }
}

  client利用java.rmi包中的Naming类的lookup()方法获得远程对象obj,然后调用其远程方法sayHello()获得字符串"Hello World",并输出到屏幕上。

  要运行这几个程序,还有一些工作要做,这几个程序的文件名为Hello.java、HelloImpl.java、HelloClient.java,它们都被放置在的的d:\hello目录下,在windows下,你需要在命令窗口中如此运行它们:

  1. Set CLASSPATH = %CLASSPATH%;d:
  2. 在d:\hello下编译源代码:
    javac -d .. *.java

  3. 在生成端头和框架模块,首先把目录切换回d:    rmic -d . hello.HelloImpl

  4. 在d:\下运行RMI远程对象注册程序
    start rmiregistry

  5. 在d:\下运行服务器程序
    java -Djava.security.policy=my.policy hello.HelloImpl

  6. 在d:\下运行客户端程序
    java -Djava.security.policy=my.policy hello.HelloClient

  其中上面的步骤中5和6出现的my.policy是一个文件,这个文件和Java的安全机制有关,在这个程序中我们不需要安全限制,所以我们把权限设为都可以访问。my.policy如下:
  grant {
      permission java.security.AllPermission;
  };

升烟 2004-03-28
  • 打赏
  • 举报
回复
关键是调用的时候指定一个参数
java -Djava.rmi.server.codebase=file:/E:\mummy\TestRMI\bin\ xxx.xxxx.YourClass
codebase指定的参数就是你的stub存放的路径
thunderxs 2004-03-28
  • 打赏
  • 举报
回复
start rmiregistry
rmic javarmi.ClockImpl
java javarmi.ClockServer

62,622

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧