RMI执行rmic生成stub类报错找不到文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Dream_Ryoma/article/details/80321777

1.配置环境变量:

    key:jdk,value:jdk安装目录jdk的bin目录下。

    key:jre,value:jdk安装目录jre的bin目录下。

    比如:我的jdk安装在E盘java文件夹中,那么新增环境变量值为:jdk---E:\Java\jdk\bin,jre---E:\Java\jre\bin。

    在path变量中添加%jdk%;%jre%。

2.在classpath环境变量中添加生成的stub类文件的保存位置。

    比如:我在classpath中添加的内容为:E:\EBRJC\RMIProject\bin\(因为我项目中.java文件生成的对应的.class文件就在该目录下)。

    注意:项目中如果类在某一个包下,那么编译的时候,对应的包会编译成一个文件夹,而classpath 中添加的内容中不能带包名生成的那个文件夹。比如我的项目中,RemoteUnicastServiceImpl.java在testRMI包中,那么编译生成的格式为testRMI文件夹中包含一个RemoteUnicastServiceImpl.class文件。而classpath中添加的应该是项目的根目录到RemoteUnicastServiceImpl.class文件所在文件夹的上一层,也就是不包含文件夹那一层。

3.生成stub类文件(只有实现了Remote接口的类才能生成stub类文件)。

   (1) 比如:我的项目名称为RMIProject,项目结构为:

    

(2)项目在本地路径为:E:\EBRJC\RMIProject;

(3)项目在本地的结构为:


.java文件生成的.class文件在bin目录下对应的文件夹中。

(4)在dos命令行执行如下命令:


第一步:进入生成的stub类文件存储的目录

第二步:执行rmic 包名.类名

rmi找不到stub

07-21

我刚开始学rmi,按照书上编了一个例子,这个例子刚开始运行好好的,在两台机子上都测试通过(没有采用动态类加载,直接把相关文件拷到客户机)。我也不知道改了什么地方,有一次运行突然就不行了,启动server时报错:Remote Error -----java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:rn java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:rn java.lang.ClassNotFoundException: RMILightBulbImp1_Stubrn rnrn classpath=.;C:\j2sdk1.4.2_02\lib Path=C:\j2sdk1.4.2_02\bin;E:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\rnbin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\Syrnstem32\WbemrnPATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSHrnrn源码:rn服务接口:rnpublic interface RMILightBulb extends java.rmi.Remotern public void on() throws java.rmi.RemoteException;rn public void off() throws java.rmi.RemoteException;rn public boolean isOn() throws java.rmi.RemoteException;rnrn服务实现rnpublic class RMILightBulbImp1 extends java.rmi.server.UnicastRemoteObject implements RMILightBulbrn public RMILightBulbImp1() throws java.rmi.RemoteExceptionrn setBulb(false);rn rnrn private boolean lightOn;rnrn public void on() throws java.rmi.RemoteExceptionrn setBulb(true);rn rnrn public void off() throws java.rmi.RemoteExceptionrn setBulb(false);rn rnrn public boolean isOn() throws java.rmi.RemoteExceptionrn return getBulb();rn rnrn public void setBulb(boolean value)rn lightOn = value;rn rnrn public boolean getBulb()rn return lightOn;rn rnrn服务器端rnimport java.rmi.*;rnimport java.rmi.server.*;rnrnpublic class LightBulbServerrn public static void main(String [] args)rn System.out.println("Loading RMI service..........");rnrn tryrn RMILightBulbImp1 bulbService = new RMILightBulbImp1();rnrn RemoteRef location = bulbService.getRef();rn System.out.println(location.remoteToString());rnrn String registry = "202.114.101.62";rn if(args.length >= 1)rn registry = args[0];rn rnrn String registration = "rmi://" + registry + "/RMILightBulb";rnrn Naming.rebind(registration,bulbService);rn rn catch(RemoteException re)rn System.err.println("Remote Error -----" + re);rn rn catch(Exception e)rn System.err.println("Error----" + e);rn rn rnrn客户端rnimport java.rmi.*;rnrnpublic class LightBulbClientrn public static void main(String[] args)rn System.out.println("Looking for looght bulb service......");rnrn tryrn String registry = "202.114.101.62";rn if(args.length >= 1)rn registry = args[0];rn rnrn String registration = "rmi://" + registry + "/RMILightBulb";rnrn Remote remoteService = Naming.lookup(registration);rnrn RMILightBulb bulbService = (RMILightBulb)remoteService;rnrn System.out.println("Invoking bulbservice.on()......");rn bulbService.on();rnrn System.out.println("Bulb state: " + bulbService.isOn());rn rn catch(NotBoundException nbe)rn System.out.println("No light bulb service available in registry!!");rn rn catch(RemoteException re)rn System.err.println("Remote Error -----" + re);rn rn catch(Exception e)rn System.err.println("Error----" + e);rn rn rnrn请高手指点!!

rmi找不到stub

07-09

我的机器用的是jdk1.5beta1,写了个简单的rmi的测试程序(import和程序的详细内容已经略去)rn以下是服务器端的程序rnpackage Server;rnpublic interface PerfectTimeI extends Remote rnrnpackage Server;rnpublic class PerfectTime extends UnicastRemoteObject implements PerfectTimeI rnrnrmiserver.policyrngrant rnpermission java.security.AllPermission;rn;rnrn我的机器上用rmic Server.PerfectTime命令只生成了PerfectTime_Stub.class,且和PerfectTime.class在同一目录下,rmiregistry已经运行.rnrn我试图运行 java -Djava.security.policy=rmiserver.policy Server.PerfectTime的时候有错误rnjava.rmi.ServerException: RemoteException occurred in server thread; nested exception is: rn java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: rn java.lang.ClassNotFoundException: Server.PerfectTime_Stubrn at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:385)rn at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)rn at sun.rmi.transport.Transport+1.run(Transport.java:153)rn at java.security.AccessController.doPrivileged(Native Method)rn at sun.rmi.transport.Transport.serviceCall(Transport.java:149)rn at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)rn at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)rn at java.lang.Thread.run(Thread.java:566)rn at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)rn at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)rn at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:343)rn at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)rn at java.rmi.Naming.bind(Naming.java:111)rn at Server.PerfectTime.main(PerfectTime.java:27)rnCaused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: rn java.lang.ClassNotFoundException: Server.PerfectTime_Stubrn at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)rn at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:375)rn at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)rn at sun.rmi.transport.Transport+1.run(Transport.java:153)rn at java.security.AccessController.doPrivileged(Native Method)rn at sun.rmi.transport.Transport.serviceCall(Transport.java:149)rn at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)rn at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)rn at java.lang.Thread.run(Thread.java:566)rnCaused by: java.lang.ClassNotFoundException: Server.PerfectTime_Stubrn at java.net.URLClassLoader+1.run(URLClassLoader.java:200)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:188)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:289)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:235)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:233)rn at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:430)rn at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)rn at java.rmi.server.RMIClassLoader+2.loadClass(RMIClassLoader.java:618)rn at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:246)rn at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)rn at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1535)rn at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1457)rn at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)rn at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1296)rn at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)rn ... 9 morernrn不知道是什么原因,尤其对java.lang.ClassNotFoundException: Server.PerfectTime_Stub不理解.请大家帮忙看看rnrnrn

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭