来自:https://stackoverflow.com/questions/27378292/launch-browser-automatically-after-spring-boot-webapp-is-ready

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class Browser {
    public static void main(String[] args) {
        String url = "http://www.google.com";

        if(Desktop.isDesktopSupported()){
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(new URI(url));
            } catch (IOException | URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }else{
            Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("xdg-open " + url);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

相关文章:

  • 2021-12-19
  • 2021-12-19
  • 2021-12-29
  • 2021-08-22
  • 2021-11-08
  • 2021-12-10
  • 2022-12-23
  • 2021-07-08
猜你喜欢
  • 2022-02-16
  • 2021-05-06
  • 2022-12-23
  • 2021-04-19
  • 2021-12-19
  • 2021-08-07
相关资源
相似解决方案