Why do I receive an error when connecting to a Java RMI Registry if it was created in a class which was called in MATLAB?
조회 수: 6 (최근 30일)
이전 댓글 표시
I have written a Java class that either uses an existing RMI registry, or creates one. See the following Java code snippet:
try {
reg = LocateRegistry.getRegistry(1099);
reg.list();
} catch (Exception e1) {
reg = LocateRegistry.createRegistry(1099);
}
See the files RMIExample.java and IRMIExample.java below for full source code.
When I instantiate the first object of this class in MATLAB:
>> a = tmw.dta.RMIExample
a =
RMIExample[UnicastServerRef [liveRef: [endpoint:[172.16.59.161:4086](local),objID:[-212c6059:11db4762d8e:-7fff, 4536923814734999922]]]]
the RMI registry is created, but then when I create a second object (which should thus connect to the registry created by the first instantiation) I receive a Java exception:
>> b = tmw.dta.RMIExample
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: tmw.dta.IRMIExample (no security manager: RMI class loader disabled)
b =
RMIExample[UnicastServerRef [liveRef: [endpoint:[172.16.59.161:4086](local),objID:[-212c6059:11db4762d8e:-7ffe, -8406764515259456100]]]]
When I create two instances of this class outside MATLAB, or when I first manually start the RMI registry, I do not receive this Java exception.
채택된 답변
MathWorks Support Team
2009년 6월 27일
You need to start a security manager before creating the RMI registry:
URL url = getClass().getResource("client.policy");
System.setProperty("java.security.policy", url.toString());
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
It is very important that the file client.policy can be found (otherwise MATLAB will crash), therefore in this example we assume that you include it in your JAR-file (or Java classpath). This ensures that it can be found using getClass().getResource. The contents of client.policy should resemble:
grant {
permission java.security.AllPermission;
};
You can apply stricter policies if your application requires it.
The attached file RMIExampleWithSecMan.java shows a fully working example class.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Java Client Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!