Mac Java: How to open a URL in a browser

A quick note here that if you need some Java code to open a URL in the default browser on a Mac OS X system, I just ran across this Java method in one of my programs that should do the trick:

private void openUrlInBrowser(String url) {
    Runtime runtime = Runtime.getRuntime();
    String[] args = { "osascript", "-e", "open location \"" + url + "\"" };
    try {
        Process process = runtime.exec(args);
    catch (IOException e) {
        // do what you want with this

Sorry, no discussion of this code today ... other than to say the "osascript" thing is Mac-specific, and there is also a newer way to do this in Java 6 (if I remember right).

Other than that, if you need a Mac Java solution to open a URL in a browser, I hope this helps.