如何使用 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 替换为您系统中的路径。一般谷歌浏览器安装在/opt/google/chrome/chrome
或者您可以像这样使用 google-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/"});
关于java - 在 Linux 和 MAC 中使用 Java 在 Chrome 中打开 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45660482/