I want to invoke a browser (e.g. Internet Explorer/Firefox/Google Chrome/Opera) via a Java interface. Also I need to pass some web links to this Java process. How to achieve this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can use the desktop API:
java.awt.Desktop.getDesktop().browse(new URI("http://stackoverflow.com")); This would launch a browser
回答2:
You can do that with Desktop#browse(). It would however only launch the system default configured browser.
回答3:
See Using the Desktop API in Java SE 6 "Opening the Browser"
回答4:
You can run the browser executable as a separate process.
Click this link on how to execute an external process in Java.