0

我尝试使用运行时命令从我的代码中运行一个 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,"");
4

1 回答 1

-1

我的建议是尝试代码中的绝对路径:

String runCommand = "java -jar /c/users/xxx/WhiteboardStudent.jar "
    + "192.168.0.3" + " " 
    + "2000" + " " 
    + "2001" + " " 
    + "test" + " 0" ;
于 2013-07-09T01:54:49.980 回答