2013-10-25 49 views
0

大家好日子! 我有問題,以我的RMI爲例。 一週前,我嘗試開始我的第一個RMI示例,它的工作,但我刪除項目,並嘗試再次創建,但我不能,因爲'拋出ExportException。 我做錯了什麼?也許我需要重新啓動rmiregistry.exe或其他東西?RMI示例和ExportException

public interface IExample extends Remote { 
    public String getMessage(String input) throws RemoteException; 
} 

public class ExampleImpl extends UnicastRemoteObject implements IExample { 
    public ExampleImpl() throws RemoteException { 
     super(); 
    } 

    @Override 
    public String getMessage(String input) throws RemoteException { 
     return "Hi " + input + "!!!"; 
    } 
    public static void main(String... args) throws RemoteException, MalformedURLException { 
     System.setSecurityManager(new RMISecurityManager()); 
     String name = "myexample"; 
     IExample engine = new ExampleImpl(); 
     IExample stub = 
       (IExample) UnicastRemoteObject.exportObject(engine, 1090); 
     Registry registry = LocateRegistry.getRegistry(); 
     registry.rebind(name, stub); 
} 
} 

P.s.所有的Thx,併爲我的英語感到抱歉。 P.p.s.和我愚蠢的問題。

+0

您應該始終發佈異常和堆棧跟蹤。 – EJP

回答

0

擴展UnicastRemoteObject的類會在構造時自動導出。你不必親自去做。除去exportObject()調用。

+0

我刪除了這個調用,並在線程「main」中獲取此異常java.security.AccessControlException:訪問被拒絕(「java.net.SocketPermission」「127.0.0.1:1099」「connect,resolve」) –

+0

擺脫安全經理。除非您使用代碼庫功能,否則不需要它。 – EJP