2013-02-11 17 views
0

我想实现以下目标,但找不到正确的解决方法。我的webapp,在某些时候使用户能够远程按buttonexecutecommand(实际执行maven buildmvn clean package)。我想要的是使用mvn command的控制台输出自动更新jsp页面,这是Jenkins在执行build时所做的。我不希望用户等待整个命令输出可用,即命令已经结束,但逐渐渲染输出(例如,每秒输出一些输出行或类似的东西)。我正在使用Spring/Spring MVC,但如果有人不得不提出没有它的解决方案,那很好。Java执行shell命令自动更新视图

我的第一个,虽然是在一个单独的thread命令行job产卵和关联用户的sessionid与正在执行该命令的threadid,但我真的不知道怎么会是最好的,从这个点出发,或者即使这是一个适当的解决方案。

有没有人做过类似的事情?有没有standard的方式来实现这样的功能?

谢谢

回答

0

我会设计这样的东西。

Upon Click 
    Generate ID 
    Start Thread for executing the Task 

Thread 
    Create an entry for this ID in a global Map 
    Start Process 
    Watch OutputStream from the Process forked for executing the build 
    Buffer to accumulate X lines 
    Re-Set the X lines of String as Value for that ID in Map 

Auto-Refresh with ID from your Page 
    Check for the String and Update Page 

也许,你可以有更多的细节,如工作是否在进行中,在地图失败或完成太方便管理。

+0

thanx为您的答案。我刚刚完成实施,我相信它正在进行。我也遵循了你的建议,并创建了一个包含各种执行信息的bean,并将其指定为全局映射的值类型。 – gpol 2013-02-11 12:10:21