Table of Contents

Fix JNLP Support in Firefox

Intro

So I couldn't get a JNLP file to open correctly through Firefox in Linux. Clicking on a .jnlp file on a web page would just bring up the download dialog instead of actually opening Java WebStart. This was pissing me off to no end. I finally had some time and the need to get this working so I dug in and figured out how to fix this. Follow the steps below and you should be up and running as well.

Check for the Java Plugin

The first thing that needs to be done is to check for the existence of a Java plugin in your browser. This, thankfully, is a simple task.

First, open Firefox (obviously) and open a tab. Type about:plugins in the tab and hit Enter. This will show you a listing of all the plugins your browser can currently use. It should look something like the following:

If you see a Java plugin, you should be good to go to move on to the next step. If not, make sure that you have Java installed and that plugin file, libjavaplugin_oji.so is in your plugins directory. This varies depending on your linux platform.

Open Your Profile's Mimetypes File

In your home directory, you should have a hidden directory named something like .mozilla, .firefox or .mozilla-firefox. On my Gentoo boxes, it's .mozilla. Open that directory.

On my Gentoo box, there is a directory in there called firefox. If you are using a distro where you have a .firefox or .mozilla-firefox directory in your home directory, you probably won't see this. Now open that firefox directory (if you have it).

In this directory you should something like this:

$ ls -l
total 13
drwx------ 7 jdeiman jdeiman 1192 May 11 10:57 g8mizwd9.default
-rw------- 1 jdeiman jdeiman 8093 May 11 10:36 pluginreg.dat
-rw-r--r-- 1 jdeiman jdeiman   94 Feb 27 12:25 profiles.ini

What we are interested in here is the <random characters>.default directory which is your default user profile. In this case, g8mizwd9.default. Open that directory.

In this directory there are a number of files and directories. The file we are interested in is mimeTypes.rdf. Open this file in your favorite text editor. You should notice quickly that this is just an XML document. Now search the file for jnlp. Hopefully, you already have an entry in here for jnlp files, but it is just misconfigured. If you don't find a line like the next block, skip down to Adding All the JNLP Entries, otherwise just continue on from here.

<RDF:li RDF:resource="urn:mimetype:application/x-java-jnlp-file"/>

Ok, so you have a reference to the mime type for jnlp files, it's just not setup correctly. If you scroll down near the bottom of the file, you should see a section like this:

<RDF:Description RDF:about="urn:mimetype:externalApplication:application/x-java-jnlp-file"
                   NC:path="/usr/bin/run-java-tool"
                   NC:prettyName="run-java-tool" />

The main thing you are looking for is the attribute RDF:about=“urn:mimetype:externalApplication:application/x-java-jnlp-file”. There are a couple other sections that look similar to this, so make sure you have the right one.

What I did, was copy this section, paste it right below the original and then comment out the original in case I made a mistake. That way I could just delete my change and uncomment the original and be back to square one. This change should look like the following:

  <!--
  <RDF:Description RDF:about="urn:mimetype:externalApplication:application/x-java-jnlp-file"
                   NC:path="/usr/bin/run-java-tool"
                   NC:prettyName="run-java-tool" />
  -->
  <RDF:Description RDF:about="urn:mimetype:externalApplication:application/x-java-jnlp-file"
                   NC:path="/usr/bin/run-java-tool"
                   NC:prettyName="run-java-tool" />

The next step is finding out where your javaws binary is. This is going to vary quite a bit between distros, but hopefully it should be an easy thing to find. I just opened a terminal window and ran a which command:

$ which javaws
/usr/bin/javaws

If the binary is in your path, you should get something similar to that for a response. If not, you can try to find it using locate or possibly :

$ find /usr -name 'javaws' -print

That will search /usr for the file, which is sometimes in libexec or some other place.

Once you've found the full path to the file, the rest is easy. Just change the NC:path and NC:prettyName in that new section we made in mimeTypes.rdf. It will end up looking like this (providing javaws is in /usr/bin):

  <!--
  <RDF:Description RDF:about="urn:mimetype:externalApplication:application/x-java-jnlp-file"
                   NC:path="/usr/bin/run-java-tool"
                   NC:prettyName="run-java-tool" />
  -->
  <RDF:Description RDF:about="urn:mimetype:externalApplication:application/x-java-jnlp-file"
                   NC:path="/usr/bin/javaws"
                   NC:prettyName="javaws" />

Now, save the file, restart Firefox, and try it out somewhere like here: http://java.sun.com/products/javawebstart/demos.html

Adding All the JNLP Entries

If you didn't have any reference to the JNLP mime type in mimeTypes.rdf, we are going to have to create them all. I would highly recommend BACKING UP YOUR ORIGINAL FILE before proceeding.

$ cp mimeTypes.rdf mimeTypes.rdf.bak

First off, I will show you my entire mimeTypes.rdf file and then we will concentrate on the specific changes that need to be made.

<?xml version="1.0"?>
<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <RDF:Description RDF:about="urn:mimetype:handler:text/nzb"
                   NC:alwaysAsk="true"
                   NC:saveToDisk="true">
    <NC:externalApplication RDF:resource="urn:mimetype:externalApplication:text/nzb"/>
  </RDF:Description>
  <RDF:Description RDF:about="urn:mimetype:externalApplication:application/x-tar"
                   NC:prettyName=""
                   NC:path="" />
  <RDF:Seq RDF:about="urn:mimetypes:root">
    <RDF:li RDF:resource="urn:mimetype:application/x-tar"/>
    <RDF:li RDF:resource="urn:mimetype:text/nzb"/>
    <RDF:li RDF:resource="urn:mimetype:application/pdf"/>
    <RDF:li RDF:resource="urn:mimetype:application/x-java-jnlp-file"/>
  </RDF:Seq>
  <RDF:Description RDF:about="urn:mimetype:externalApplication:application/pdf"
                   NC:path="/usr/local/Adobe/Acrobat7.0/bin/acroread"
                   NC:prettyName="acroread" />
  <RDF:Description RDF:about="urn:mimetype:application/x-java-jnlp-file"
                   NC:fileExtensions="jnlp"
                   NC:description=""
                   NC:value="application/x-java-jnlp-file"
                   NC:editable="true">
    <NC:handlerProp RDF:resource="urn:mimetype:handler:application/x-java-jnlp-file"/>
  </RDF:Description>
  <RDF:Description RDF:about="urn:mimetype:application/x-tar"
                   NC:value="application/x-tar"
                   NC:editable="true"
                   NC:fileExtensions="tar"
                   NC:description="">
    <NC:handlerProp RDF:resource="urn:mimetype:handler:application/x-tar"/>
  </RDF:Description>
  <RDF:Description RDF:about="urn:mimetypes">
    <NC:MIME-types RDF:resource="urn:mimetypes:root"/>
  </RDF:Description>
  <RDF:Description RDF:about="urn:mimetype:handler:application/x-tar"
                   NC:alwaysAsk="true"
                   NC:saveToDisk="true">
    <NC:externalApplication RDF:resource="urn:mimetype:externalApplication:application/x-tar"/>
  </RDF:Description>
  <RDF:Description RDF:about="urn:mimetype:handler:application/x-java-jnlp-file"
                   NC:alwaysAsk="false"
                   NC:saveToDisk="false"
                   NC:useSystemDefault="false"
                   NC:handleInternal="false">
    <NC:externalApplication RDF:resource="urn:mimetype:externalApplication:application/x-java-jnlp-file"/>
  </RDF:Description>
  <RDF:Description RDF:about="urn:mimetype:handler:application/pdf"
                   NC:alwaysAsk="true"
                   NC:saveToDisk="false"
                   NC:useSystemDefault="false"
                   NC:handleInternal="false">
    <NC:externalApplication RDF:resource="urn:mimetype:externalApplication:application/pdf"/>
  </RDF:Description>
  <RDF:Description RDF:about="urn:mimetype:text/nzb"
                   NC:value="text/nzb"
                   NC:editable="true"
                   NC:description="">
    <NC:handlerProp RDF:resource="urn:mimetype:handler:text/nzb"/>
  </RDF:Description>
  <!--
  <RDF:Description RDF:about="urn:mimetype:externalApplication:application/x-java-jnlp-file"
                   NC:path="/usr/bin/run-java-tool"
                   NC:prettyName="run-java-tool" />
  -->
  <RDF:Description RDF:about="urn:mimetype:externalApplication:application/x-java-jnlp-file"
                   NC:path="/usr/bin/javaws"
                   NC:prettyName="javaws" />
  <RDF:Description RDF:about="urn:mimetype:externalApplication:text/nzb"
                   NC:prettyName=""
                   NC:path="" />
  <RDF:Description RDF:about="urn:mimetype:application/pdf"
                   NC:value="application/pdf"
                   NC:editable="true"
                   NC:fileExtensions="pdf"
                   NC:description="">
    <NC:handlerProp RDF:resource="urn:mimetype:handler:application/pdf"/>
  </RDF:Description>
</RDF:RDF>

Ok, so, to start, you need to add the following line in the section <RDF:Seq RDF:about=“urn:mimetypes:root”>:

  <RDF:li RDF:resource="urn:mimetype:application/x-java-jnlp-file"/>

After that section, specifically after the line, </RDF:Seq>, we need to add the following:

  <RDF:Description RDF:about="urn:mimetype:application/x-java-jnlp-file"
                   NC:fileExtensions="jnlp"
                   NC:description=""
                   NC:value="application/x-java-jnlp-file"
                   NC:editable="true">
    <NC:handlerProp RDF:resource="urn:mimetype:handler:application/x-java-jnlp-file"/>
  </RDF:Description>

Below that, add this:

  <RDF:Description RDF:about="urn:mimetype:handler:application/x-java-jnlp-file"
                   NC:alwaysAsk="false"
                   NC:saveToDisk="false"
                   NC:useSystemDefault="false"
                   NC:handleInternal="false">
    <NC:externalApplication RDF:resource="urn:mimetype:externalApplication:application/x-java-jnlp-file"/>
  </RDF:Description>

Almost done, one more section to add:

<RDF:Description RDF:about="urn:mimetype:externalApplication:application/x-java-jnlp-file"
                   NC:path="/usr/bin/javaws"
                   NC:prettyName="javaws" />

You should be able to save the file, restart Firefox and test out the changes at some place like http://java.sun.com/products/javawebstart/demos.html

~~DISCUSSION~~