问题
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?
回答1:
I've not tried it in JNLP, but normally this should work:
java.awt.Desktop.getDesktop().browse(new URI("http://www.sun.com"));
回答2:
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).
回答3:
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;
}
}
来源:https://stackoverflow.com/questions/1119591/launching-a-browser-window-from-java-webstart-jnlp-in-java-6u13