I was wondering if there was a standard way to open URLs in the users default browser. I've been using the desktop.browse() way, but after a bit of testing I can't seem to make this work on OSX while it works fine on Windows. My attempts at research have brought up mostly old articles, so I thought there may be a more modern method I can't find. Ideally there would be one approach that could work for every system, but lacking that I can always make it branch off by system. So my questions are this:
java.awt.Desktop
is the class you're looking for.
import java.awt.Desktop;
import java.net.URI;
// ...
if(Desktop.isDesktopSupported())
{
Desktop.getDesktop().browse(new URI("http://www.example.com"));
}
That is what I would do. answer comes from this site at :: How to open the default webbrowser using java
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