Associate file type with Java Swing application

后端 未结 1 682
鱼传尺愫
鱼传尺愫 2020-12-11 04:53

I am creating a java swing application and I need to set the my program as the default program for the file extension .mcsd (MIME type text/mcsd).

相关标签:
1条回答
  • 2020-12-11 05:39

    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.

    0 讨论(0)
提交回复
热议问题