
正文
spring-boot启动后在浏览器打开指定页面
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
来自: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();
}
}
}
}






