Associate file type with Java Swing application

纵饮孤独 提交于 2019-11-28 12:22:30
Andrew Thompson

Deploy the app. with Java Web Start:

JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update ..

See the file services demo. for an example of a JNLP that declares an interest in the .zzz file type.

This is how the association is declared in the JNLP:

<association
  extensions="zzz"
  mime-type="text/sleepytime" />

JWS is supplied by Oracle and works on Windows, *nix & OS X.

..but I would prefer not to use the Java Web Start. Because I would like to have a native installer that just installs the program, without opening a web page or anything. If that's not how (web start) works, then I'm happy to use it.

JWS works over the web or a network. But if you can invoke the opening of an URL (to the JNLP) from the desktop, there does not need to be any browser opened.

Would I do that using openConnection() on a URL object?

I would use the Desktop or BasicService API.

Desktop.getDesktop().browse(uri);

boolean result = basicService.showDocument(url);

As noted in the BasicService demo.

In Java 6+, a call to show another web start launch file (e.g. BasicService.showDocument(another.jnlp)) will be handed directly to JavaWS, with no browser window appearing.

I expect this has always been true of the Desktop API, given the JWS client is the default consumer for that file type.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!