如何从Java异步运行JBoss服务器应用程序

如何从Java异步运行JBoss服务器应用程序,java,spring-boot,server,jboss,Java,Spring Boot,Server,Jboss,在我的java应用程序中,我需要使用文件standalone.bat运行Jboss服务器 我尝试了ProcessBuilder,虽然它确实启动了服务器,但我的应用程序在等待服务器关闭时被阻止 @RequestMapping(value = "api/project/liststart", method = RequestMethod.POST) public HttpEntity<Boolean> postListServer(@RequestBody ListSta

在我的java应用程序中,我需要使用文件
standalone.bat
运行Jboss服务器

我尝试了
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;
    }


}
@RequestMapping(value=“api/project/liststart”,method=RequestMethod.POST)
公共HttpEntity postListServer(@RequestBody ListStart模块)抛出可丢弃的{
字符串cmd=“”;
布尔响应=假;
ProcessBuilder ProcessBuilder=新的ProcessBuilder();
String path=“C:\\jboss-as-7.1.1.Final\\bin\\”;
String命令=standelone.bat+“>sometext.txt”;
processBuilder.command(“cmd.exe”,“/c”,command);
目录(新文件(路径));
Process=processBuilder.start();
缓冲读取器=
新的BufferedReader(新的InputStreamReader(process.getInputStream());
弦线;
而((ligne=reader.readLine())!=null){
系统输出打印LN(ligne);
}
int exitCode=process.waitFor();
System.out.println(“\n包含错误代码:“+exitCode”);
字符串F=path+“\\SomeFile.txt”;
System.out.println(“---------------------------文件:+F”);
文件文件=新文件(F);
扫描仪=新扫描仪(文件);
//现在逐行读取文件。。。
int lineNum=0;
while(scanner.hasNextLine()){
字符串行=scanner.nextLine();
lineNum++;
if(第行包含(“已启动服务器”)){
响应=真;
System.out.println(“------------------------------------”+response.toString());
}
}
ResponseEntity ResponseEntity=新的ResponseEntity(response,HttpStatus.OK);
返回响应性;
}
}

我希望上面的方法返回
true
值,但是在返回值之前它被阻止了。

看起来像是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);
}
            }
while(scanner.hasNextLine()){
字符串行=scanner.nextLine();
lineNum++;
if(第行包含(“已启动服务器”)){
响应=真;
System.out.println(“------------------------------------”+response.toString());
返回新的ResponseEntity(response,HttpStatus.OK);
}否则{
返回新的ResponseEntity(response,HttpStatus.OK);
}
}

我添加了一个中断;在while cycleAre中,如果(line.contains(“Started server”)),是否确保执行进入该语句?