I have found 2 ways to open a url in an external browser in an Eclipse application.
Any clues on which way is better? (portability, reliability, ...)
1- simple straight forward use System default:
org.eclipse.swt.program.Program.launch(url)
2- Use browser support to open external browser:
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(url)
The code for (1) looks simple but there must be a reason why eclipse provide the BrowserSupport :) Can someone please educate me.
There is no 'better' in this case, if you're just firing off URLs, you can use either mechanism to the same effect.
Firstly, the simple operation will only ever open the system defined external browser, and that's it; it get's handed off and you never get to interact with it at all.
The getBrowserSupport().getExternalBrowser()
will allow you to interact with the browser - e.g. the close()
call might actually close the browser.
The more likely reason you'll be interacting with getBrowserSupport()
is to work with the (potentially supplied) internal browser.
For AWT/Swing apps there's also:
java.awt.Desktop.getDesktop().browse(new URI(url));
which would accomplish the same thing as the Program.launch()
call with the url.
The other thing you can do with Program.launch()
is to open documents, folders, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With