码迷,mamicode.com
首页 > 其他好文 > 详细

在春天结束JVM当浏览器选项卡关闭启动应用程序

时间:2018-12-11 19:48:44      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:time   rom   man   web   运行   打开   contex   class   except   

我有一个spring-boot web应用程序分配jar文件。 启动应用程序的代码如下:

private static ConfigurableApplicationContext ctx;

public static void main(String[] args){

    if(ctx == null) {
        ctx = SpringApplication.run(MyApplication.class, args);
    }       
    try {
        openHomePage("http://localhost:8090/");
    }catch(Exception e) {
        logger.error("Error occured starting the application: ", e);
        ctx.close();
    }

}

private static void openHomePage(String url) throws IOException, URISyntaxException {
if(Desktop.isDesktopSupported()) {
URI homePage = new URI(url);
Desktop.getDesktop().browse(homePage);
}else {
Runtime runtime = Runtime.getRuntime();
runtime.exec(new String[]{"cmd", "/c","start chrome " + url});
}

}

打开主页Chrome当我运行它Eclipse通过双击jar文件。

问题是当我从启动应用程序jar文件并关闭浏览器选项卡,应用程序继续运行JVM我必须杀了它task manager手动是烦人的。 如果我不杀死JVM然后再双击jar文件,应用程序不会自动启动,第一次,我必须手动打开一个新的浏览器选项卡和类型http://localhost:8090 /为了使用该应用程序。

有可能杀死每个进程在用户关闭浏览器选项卡,这样当他们下次点击jar文件需要使用应用程序,自动将打开一个新的浏览器选项卡吗?

在春天结束JVM当浏览器选项卡关闭启动应用程序

标签:time   rom   man   web   运行   打开   contex   class   except   

原文地址:http://blog.51cto.com/14021402/2329055

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!