java.rmi.UnmarshalException:errorunmarshalling return; java.lang.ClassNotFoundException的解决方法
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                java.rmi.UnmarshalException:errorunmarshalling  return; java.lang.ClassNotFoundException的解决方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                1)problem
出現?java.rmi.UnmarshalException: ? error ? unmarshalling ? return; ? nested ? exception ? is: ??
 
java.lang.ClassNotFoundException 異常的原因是,在命令行執行 rmiregistry,并沒有指定好 綁定時查找的類文件的路徑。
2)solution
 
以上圖片是我的一個荔枝,我的需要綁定的類所屬類名如下:
package com.corejava.chapter11.activation.server;import java.rmi.*;/**The remote interface for a simple warehouse.@version 1.0 2007-10-09@author Cay Horstmann */ // 遠程對象的接口必須擴展Remote接口 public interface Warehouse extends Remote { double getPrice(String description) throws RemoteException; }
 
)時,1099是 rmiregistry的啟動默認端口,發送該綁定請求后,registry 就會去查找要綁定的 centralWarehouse 所屬的類名,也即是 com.corejava.chapter11.activation.server.Warehouse。
 
package com.corejava.chapter11.activation.server;import java.io.*; import java.rmi.*; import java.rmi.activation.*; import java.util.*;import javax.naming.*;public class WarehouseActivator {public static void main(String[] args) throws RemoteException,NamingException, ActivationException, IOException,AlreadyBoundException{System.out.println("Constructing activation descriptors...");System.setProperty("java.security.policy","com/corejava/chapter11/activation/server/server.policy");System.setSecurityManager(new SecurityManager());// 如何構建激活程序Properties props = new Properties();// use the server.policy file in the current directoryprops.put("java.security.policy", new File("com/corejava/chapter11/activation/server/server.policy").getCanonicalPath());// step1)需要定義一個激活組// step2) 然后如下構造一個激活組描述符:ActivationGroupDesc group = new ActivationGroupDesc(props, null);// step3)創建一個組IDActivationGroupID id = ActivationGroup.getSystem().registerGroup(group);Map<String, Double> prices = new HashMap<>();prices.put("Blackwell Toaster", 24.95);prices.put("ZapXpress Microwave Oven", 49.95);MarshalledObject<Map<String, Double>> param = new MarshalledObject<Map<String, Double>>(prices);String codebase = "http://localhost:8080/";// step4) 構造一個激活描述符了。對于需要構造的每一個對象,都應該包括以下內容(contents):// 激活組ID + 類的名字 + URL字符串 + 編組后的構造信息// LocateRegistry.createRegistry(1099);ActivationDesc desc = new ActivationDesc(id,"com.corejava.chapter11.activation.server.WarehouseImpl",codebase, param);Warehouse centralWarehouse = (Warehouse) Activatable.register(desc);Naming.rebind("rmi://localhost:1099/central_warehouse", centralWarehouse);System.out.println("Exiting...");} }
總結
以上是生活随笔為你收集整理的java.rmi.UnmarshalException:errorunmarshalling return; java.lang.ClassNotFoundException的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 三叶草代表什么意思 三叶草代表啥意思
- 下一篇: 真假东宫电视剧 真假东宫电视剧讲述了什么
