0

The Java Web Start technology has an IntegrationService API for creating file associations. My question is whether it is possible to somehow use this API (possibly by including jnlp.jar in my app) to create file associations, but without the full Java Web Start technology (no website for the initial installation, the program is distributed with a traditional installer or as a simple executable jar file). The app in question is a desktop/swing app.

(This question arose in the comments of the question How to associate a file with a program in java)

Community
  • 1
  • 1
lbalazscs
  • 17,474
  • 7
  • 42
  • 50

1 Answers1

3

No web site is required to use a jnlp file locally, just use a file URI scheme for the jnlp codebase and jar href.

This will let you experiment with file associations, but you'll want to do a backup and clean the Java Preferences cache first.

Addenda:

  • As a concrete example, this jnlp launches JFreeChart:

    <?xml version="1.0" encoding="utf-8"?>
    <jnlp spec="1.0+" 
            codebase="file:///Users/trashgod/jnlp/"
            href="jfreechart-1.0.14-demo.jnlp">
        <information>
            <title>JFreeChart 1.0.14 Demo</title>
            <vendor>Object Refinery Ltd</vendor>
            <homepage href="http://www.object-refinery.com/" />
            <description>A demo for the JFreeChart class library</description>
            <description kind="short">JFreeChart demo application.</description>
            <description kind="tooltip">JFreeChart 1.0.14 Demo</description>
            <offline-allowed />
        </information>
        <resources>
            <j2se version="1.5+" initial-heap-size="12m" max-heap-size="256m" />
            <jar href="file:///opt/jfreechart/jfreechart-1.0.14-demo.jar" />
            <jar href="file:///opt/jfreechart/lib/jcommon-1.0.17.jar" />
            <jar href="file:///opt/jfreechart/lib/jfreechart-1.0.14.jar" />
        </resources>
        <application-desc main-class="demo.SuperDemo" />
    </jnlp>
    
  • The <association/> tag uses the attributes mime-type and extensions as "a hint to the JNLP client that it wishes to be registered with the operating system as the primary handler of certain extensions and a certain mime-type."

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • For testing JWS apps. I would typically use a local server or Ant (specifying the pseudo-codebase in the `javaws` invocation), though I recently have been trying to force myself to use Eclipse and have not got 'running JWS apps.' sorted out yet. – Andrew Thompson Sep 08 '12 at 02:14
  • Are you using the [*Ant Web Start Task*](http://ant-jnlp-war.sourceforge.net/)? On Mac OS, a `jnlp` file is just another document with an association to `javaws`. Such files can reside comfortably in the dock or recent items menu. – trashgod Sep 08 '12 at 10:41
  • *"Are you using the Ant Web Start Task?"* No, but I'll give it a try in the near future. – Andrew Thompson Sep 08 '12 at 11:05
  • The user would still have to click on the local JNLP file or this click could be done programmatically? (Suppose I have a "Manage File Associations" dialog in my app - it would be strange to require clicking on local files) – lbalazscs Sep 08 '12 at 12:47
  • @lbalazscs: It may help to distinguish the following: 1) the association between a `jnlp` file and `javaws`, which launches the application, and 2) the association between a particular mime type and certain extensions, which is created in the `` tag. More above. – trashgod Sep 08 '12 at 13:28