Question

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?

Was it helpful?

Solution

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

java.awt.Desktop.getDesktop().browse(new URI("http://www.sun.com"));

OTHER TIPS

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).

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;
    }       
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top