CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2EE / EJB / JMS

一个很简单的rmi的例子,可是却出错!急!

楼主liuchang2859(liuchang)2004-12-04 17:17:54 在 Java / J2EE / EJB / JMS 提问

一个core   java   2书上的最简单的例子。  
   
  Product.java:  
   
  import   java.rmi.*;  
     
      /**  
            The   interface   for   remote   product   objects.  
      */  
      public   interface   Product   extends   Remote  
      {  
            /**  
                  Gets   the   description   of   this   product.  
                @return   the   product   description  
          */  
          String   getDescription()   throws   RemoteException;  
    }  
  ProductClient.java  
   
    import   java.rmi.*;  
      import   java.rmi.server.*;  
     
      /**  
            This   program   demonstrates   how   to   call   a   remote   method  
            on   two   objects   that   are   located   through   the   naming   service.  
      */  
      public   class   ProductClient  
      {  
          public   static   void   main(String[]   args)  
          {  
                System.setProperty("java.security.policy",   "client.policy");  
                System.setSecurityManager(new   RMISecurityManager());  
                String   url   =   "rmi://localhost/";  
                      //   change   to   "rmi://yourserver.com/"  
                      //   when   server   runs   on   remote   machine  
                      //   yourserver.com  
                      try  
                {  
                      Product   c1   =   (Product)Naming.lookup(url   +   "toaster");  
                      Product   c2   =   (Product)Naming.lookup(url   +   "microwave");  
                      System.out.println(c1.getDescription());  
                      System.out.println(c2.getDescription());  
                }  
                catch(Exception   e)  
                {  
                      e.printStackTrace();  
                }  
          }  
    }  
   
  ProductImpl.java:  
   
  import   java.rmi.*;  
  import   java.rmi.server.*;  
   
    /**  
          This   is   the   implementation   class   for   the   remote   product  
          objects.  
    */  
    public   class   ProductImpl  
          extends   UnicastRemoteObject  
          implements   Product  
    {  
          /**  
                Constructs   a   product   implementation  
                @param   n   the   product   name  
          */  
          public   ProductImpl(String   n)   throws   RemoteException  
          {  
                name   =   n;  
          }  
   
          public   String   getDescription()   throws   RemoteException  
          {  
                return   "I   am   a   "   +   name   +   ".   Buy   me!";  
          }  
   
          private   String   name;  
           
    }  
   
  ProductServer.java  
   
  import   java.rmi.*;  
  import   java.rmi.server.*;  
    /**         This   server   program   instantiates   two   remote   objects,  
    6.         registers   them   with   the   naming   service,   and   waits   for  
    7.         clients   to   invoke   methods   on   the   remote   objects.  
    8.   */  
  public   class   ProductServer  
  {  
      public   static   void   main(String   args[])  
      {  
            try  
            {  
                  System.out.println  
                        ("Constructing   server   implementations...");  
   
                  ProductImpl   p1  
                        =   new   ProductImpl("Blackwell   Toaster");  
                  ProductImpl   p2  
                        =   new   ProductImpl("ZapXpress   Microwave   Oven");  
   
                  System.out.println  
                        ("Binding   server   implementations   to   registry...");  
   
                  Naming.rebind("toaster",   p1);  
                  Naming.rebind("microwave",   p2);  
   
                  System.out.println  
                        ("Waiting   for   invocations   from   clients...");  
            }  
            catch(Exception   e)  
            {  
                  e.printStackTrace();  
            }  
      }  
  }  
   
   
  按照书上的步骤,编译都可以通过  
   
  但是到第2步rmic   -v1.2   ProductImpl  
  却出错:error:   Class   ProductImpl   not   found.  
   
  我之前还实现过,但是不知道为什么?中间动过环境变量。其他的java   application程序都可以运行。  
   
  谢了!!!  
   
  问题点数:50、回复次数:4Top

1 楼jFresH_MaN(十一月的萧邦-夜曲)回复于 2004-12-04 17:23:48 得分 50

classpath里面的那个点有没有漏掉Top

2 楼liusoft(红薯)回复于 2004-12-04 17:27:43 得分 0

rmic   -classpath   .   ProductImpl  
   
  http://www.javayou.comTop

3 楼liuchang2859(liuchang)回复于 2004-12-04 18:02:36 得分 0

什么点?  
   
  后面的说的是什么意思?谢Top

4 楼liuchang2859(liuchang)回复于 2004-12-04 18:08:52 得分 0

classpath里应该是什么  
  我现在是:D:\jakarta-tomcat-5.0.16\common\lib\servlet-api.jar;  
   
  应该改成什么?  
   
  Top

相关问题

  • 一个最简单的RMI调用的例子,为什么出错,郁闷
  • Webwork的简单例子出错
  • 初学者:JB5的RMI例子出错,错在哪里?
  • 简单例子程序连接出错,求救!
  • axis 的一个简单例子出错,高分求救!
  • 关于消息的使用的简单例子,但出错,请指点
  • CB的例子,出错,
  • struts例子运行出错
  • RMI出错,咋办?
  • 参考了夏昕 Spring_Dev_Guide做个简单的登录例子出错了,请大家指点一下。

关键词

  • server
  • productimpl
  • rmi
  • getdescription
  • toaster
  • microwave
  • remote
  • remoteexception
  • product
  • implementations

得分解答快速导航

  • 帖主:liuchang2859
  • jFresH_MaN

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo