we\'re writing an open-source jdbc driver for bigquery, and ran into the following problem:
We want to authorize our driver with Oauth 2 as an installed application.
Basically sounds good but here is another way if you want to open using specific browser (if more than one browser in the system)
String url = "http:/devmain.blogspot.com/";
String[] browsers = { "firefox", "opera", "mozilla", "netscape" }; // common browser names
String browser = null;
for (int count = 0; count < browsers.length && browser == null; count++)
if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0)
browser = browsers[count]; // have found a browser
Runtime.getRuntime().exec(new String[] { browser, url }) // open using a browser
More details here: http://devmain.blogspot.com/2013/10/java-how-to-open-url-in-browser.html
Here is a suggestion from a different perspective. (Not sure if this is an option to you)
The problem that you are trying to solve is to use Oauth 2 and authentication mechanism. Instead of opening a browser capturing its response. There are already available libraries like Apache amber which do this purely in java.
Here is an official Amber Example that you can refer to.
Using java.net.HttpURLConnection
URL myURL = new URL("http://example.com/");
URLConnection myURLConnection = myURL.openConnection();
myURLConnection.connect();