我尝试使用运行时命令从我的代码运行一个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,"");
答案 0 :(得分:-1)
我的建议是尝试代码中的绝对路径:
String runCommand = "java -jar /c/users/xxx/WhiteboardStudent.jar "
+ "192.168.0.3" + " "
+ "2000" + " "
+ "2001" + " "
+ "test" + " 0" ;