Launch Default Web Browser in Java

For the longest time I’ve used the BrowserLauncher library to open the default web browser to a specified web page from Java. BrowserLauncher is simple to use, just import edu.stanford.ejalbert.BrowserLauncher and call openURL method with the desired website URL.

Since Java 1.6, the JDK has introduced the java.awt.Desktop class to do the same so you don’t need an additional third party jar. The Desktop class has the ability to launch the desktop’s default email client and default web browser given a URI. Here is how you can launch the desktop’s default web browser in Java.

// Launch your default email client with ...
URI email = new URI("mailto:myemail@mydomain.com");
Desktop.getDesktop().mail(email);

// Launch your default web browser with ...
URI url = new URI("http://www.mydomain.com");
Desktop.getDesktop().browse(url);

Related posts:

  1. Seamless Web Browser Integration
  2. Creating Internet Shortcuts in Windows
  3. Run PHP Web Applications on the Java Platform
  4. Putting a Swing Front End on a Web Application
  5. Component Based Java Web Development with Apache Wicket
  6. Java Web Service with HTTPS


One Response to “Launch Default Web Browser in Java”

Leave a Reply