2010-04-21 3 views
-1

현재 rmi 레지스트리를 사용하여 원격 환경에서 작업하고 있습니다. 내 서버는 다음과 같이이다 : 나는하여 프로그램을 실행하면RMI 레지스트리가 실패했습니다 ... 예외가 null입니다.

 
import java.rmi.registry.LocateRegistry; 
import java.rmi.registry.Registry; 


public class Server { 
    public static void main(String args[]){ 
     if(args.length"); 
      System.exit(-1); 
     }  
     try{ 
      Registry r=LocateRegistry.getRegistry(); 
     MethodsImp methods=new MethodsImp(); 
      //have the object to be remotely accessed so will bind it to the registry 
      System.out.println("Will register on "+args[0]); 
      r.rebind(args[0], methods); 
     } 
     catch(Exception e){ 
      System.out.println("Something went wrong when registring the methods"); 
      System.out.println(e.getMessage()); 
      System.exit(-1); 
     } 

    } 

} 

:

 
java -classpath /home/outsider/Desktop/RIM/RIM_TP1_correct/src -Djava.rmi.server.codebase=file:/home/outsider/Desktop/RIM/RIM_TP1_correct/src/ Server regsiter_name 

나는이 얻을 : 어떤 이유로

Will register on regsiter_name 
Something went wrong when registring the methods 
null 

을 나는 그것이를 throw r.rebind 사용하는 경우 메세지가 null의 예외. 프로그램을 실행하기 전에 내가 쉘에

rmiregistry &

를 수행하여 rmiregistry에 설치합니다. 내가 뭘 잘못하고 있는지 알 수 없습니다. 사람이 좋은 것입니다 도움이 될 수 경우

+0

어떤 유형의 예외가 발생합니까? ...? 'System.out.println (e.getClass(). getSimpleName()); 시도하십시오. – Finbarr

+0

그것은 NullPointerException을 제공합니다 .... 그게 r.rebind가 제대로 작동하지 않는 것 같습니다 ....하지만 그렇지 않습니다. 이유를 아십니까 –

+0

코드가 컴파일되지 않고 스택 추적을 제공하지 않았습니다. 현재 형태로 답할 수 없음. – EJP

답변

0

코드의 문제는 당신이 당신의 원격 객체를

MethodsImp 방법 = 새 MethodsImp()를 내보낼 필요가있다;

을 rmi 레지스트리에 지정하십시오.

이 코드를

MethodsImp methods=new MethodsImp(); 
Hello stub = (Hello) UnicastRemoteObject.exportObject(methods, 0); 

안녕을 포함하여 그것을 할 수있는 인터페이스의 이름입니다.

이 코드는 개체를 레지스트리로 내 보냅니다. 인터페이스를 구현하고 동일한 클래스에서 오브젝트를 바인딩하는 경우 오브젝트를 익스포트 할 필요가 없습니다. 다른 클래스를 사용하여 오브젝트를 바인드하는 경우 오브젝트를 익스포트해야합니다.

+0

당신은 그것을 모릅니다. 대부분의 리모트 오브젝트는'UnicastRemoteObject'를 확장 해, 명시 적으로 export 할 필요는 없습니다. 스택 추적없이 문제가 무엇인지 알 수 없습니다. – EJP

+0

그리고 'RMI 레지스트리로 내보내기'와 같은 것은 없습니다. 수출, 기간이 있고 레지스트리에 * 구속력이 있습니다. – EJP