我正在运行一个 xSocket 服务器,因此需要启动一个 chat.jar,它似乎没有调用该部分。我的代码有什么问题?
如果我创建一个 xSocketserver.jar,那么 exec 是否能够启动任何外部 jar?
import java.io.*;
import org.xsocket.connection.*;
public class xSocketServer
{
protected static IServer srv = null;
public static void main(String[] args)
{
try {
srv = new Server("127.0.0.1",8090, new xSocketDataHandler());
srv.run();
}
catch(Exception ex) {
System.out.println(ex.getMessage());
}
try {
System.out.println("setup exec");
Process p = Runtime.getRuntime().exec("cmd java -jar D:\\chat.jar -n 0");
p.waitFor();
System.out.println("call exec");
}
catch(Exception ex) {
System.out.println(ex.getMessage());
}
}
protected static void shutdownServer() {
try {
srv.close();
}
catch(Exception ex) {
System.out.println(ex.getMessage());
}
}
}