我尝试使用运行时命令从我的代码中运行一个 jar。jar 通过 RMI 连接到另一台主机。它通过异常并退出。
但是当我从 cmd 打开 jar 时它工作正常。
jar 有 5 个参数。
代码 :
String runCommand = "java -jar WhiteboardStudent.jar "
+ "192.168.0.3" + " "
+ "2000" + " "
+ "2001" + " "
+ "test" + " 0" ;
final Process proc = Runtime
.getRuntime()
.exec(runCommand,null,new File("util/"));
命令提示符 :
java -jar WhiteboardStudent.jar 192.168.0.3 2000 2001 test 0
抛出异常的代码在这里:
Object proxy = registry.lookup("RWD");
Whiteboard whiteboard = (Whiteboard)proxy;
我只是难住了。有什么想法吗?
抛出异常的函数:
Registry registry = LocateRegistry.getRegistry(
hostname, Integer.parseInt(whiteboardPort)
);
String serviceName = "RemoteWhiteboard" + sessionID;
Object proxy = registry.lookup(serviceName);
Whiteboard whiteboard = (Whiteboard)proxy;
int userid = whiteboard.userRegistry(userName, "");
Main mainFrame = new Main(sessions, sessionID,
whiteboard,userid,"");