views:

405

answers:

3

There is a bug in Java 6u13 and 6u14. http://bugs.sun.com/view_bug.do?bug_id=6835450

Simply put, the following code is supposed to open a browser window, but because of a bug in the framework, it stopped working in Java 1.6 update 13. Nothing opens anymore. There was a similar bug for Java applets (that was fixed in update 14), but this one still exists in update 14 for Java WebStart/JNLP.

getAppletContext().showDocument(new URL("http://www.sun.com"),"_blank");

Do you know of any workarounds?

+4  A: 

I've not tried it in JNLP, but normally this should work:

java.awt.Desktop.getDesktop().browse(new URI("http://www.sun.com"));
Joachim Sauer
It's URI in this case, but appears to work fine. Can't specify the target, but this is good enough for me.
Jason Kealey
A: 

Does BasicService.showDocument work? I can't remember how that is implemented off hand.

Alternatively, use LiveConnect to execute JavaScript yourself (although that might run into the same problems).

Tom Hawtin - tackline
A: 
public boolean openUrl(final URL url) {
    try {
        // Lookup the javax.jnlp.BasicService object
        BasicService bs = (BasicService)javax.jnlp.ServiceManager.lookup("javax.jnlp.BasicService");
        // Invoke the showDocument method
        return bs.showDocument(url);
    } catch(UnavailableServiceException ue) {
        // Service is not supported
        log.log(Level.WARNING, "Could not open URL " + url, ue);
        return false;
    }       
}
Sam Barnum
I'm not sure why you're posting this late. This problem was supposedly fixed in Java 6u18.
R. Bemrose