如何使用Java启动chrome?
对于Windows,代码如下所示。

Runtime.getRuntime().exec(new String[]{"cmd", "/c", "start chrome http://localhost:8080"});

上面有类似的东西吗?

最佳答案

在Linux中,您可以这样使用:

Runtime.getRuntime().exec(new String[]{"bash", "-c", "/path/to/chrome http://yourwebsite.com"});

将/path/to/chrome替换为系统中的路径。通常Google Chrome安装在/opt/Google/Chrome/Chrome
或者你可以像这样使用谷歌浏览器:
Runtime.getRuntime().exec(new String[]{"bash", "-c", "google-chrome http://yourwebsite.com"});

如果要在Linux中的chromium浏览器中打开,请按如下方式使用:
Runtime.getRuntime().exec(new String[]{"bash", "-c", "chromium-browser http://yourwebsite.com"});

对于MAC OS,请尝试以下操作:
Runtime.getRuntime().exec(new String[]{"/usr/bin/open", "-a", "/Applications/Google Chrome.app", "http://yourwebsite.com/"});

07-24 09:45
查看更多