[英]How to asynchronously run JBoss server application from Java
In my java application, I need to run a Jboss server with the file standalone.bat
.在我的 java 应用程序中,我需要使用文件
standalone.bat
运行一个 Jboss 服务器。
I tried ProcessBuilder
, and though it did start the server, my application is blocked waiting for the server to go down我尝试了
ProcessBuilder
,虽然它确实启动了服务器,但我的应用程序被阻止等待服务器关闭
@RequestMapping(value = "api/project/liststart", method = RequestMethod.POST)
public HttpEntity<Boolean> postListServer(@RequestBody ListStart modules) throws Throwable {
String cmd = "";
Boolean response = false;
ProcessBuilder processBuilder = new ProcessBuilder();
String path = "C:\\jboss-as-7.1.1.Final\\bin\\";
String command = standelone.bat+ " >sometext.txt" ;
processBuilder.command("cmd.exe", "/c", command);
processBuilder.directory(new File(path));
Process process = processBuilder.start();
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
String ligne;
while ((ligne = reader.readLine()) != null) {
System.out.println(ligne);
}
int exitCode = process.waitFor();
System.out.println("\nExited with error code : " + exitCode);
String F = path + "\\SomeFile.txt";
System.out.println("------------------------file: " + F);
File file = new File(F);
Scanner scanner = new Scanner(file);
//now read the file line by line...
int lineNum = 0;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
lineNum++;
if (line.contains("Started server")) {
response = true;
System.out.println("-------------------------------------" + response.toString());
}
}
ResponseEntity responseEntity = new ResponseEntity<Boolean>(response, HttpStatus.OK);
return responseEntity;
}
}
I expect the method above to return true
value, but it's being blocked before a value can be returned.我希望上面的方法返回
true
值,但是在返回值之前它被阻止了。
It seems like scanner.hasNextLine() can't get out from while cycle, so try like this :似乎scanner.hasNextLine() 无法从while 循环中退出,所以尝试这样:
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
lineNum++;
if (line.contains("Started server")) {
response = true;
System.out.println("-------------------------------------" + response.toString());
return new ResponseEntity<Boolean>(response, HttpStatus.OK);
} else {
return new ResponseEntity<Boolean>(response, HttpStatus.OK);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.