Pages

November 23, 2011

Installing Oracle Java in Wheezy

This is going to be something of a living document. Earlier today I moaned about how Oracle's Java has been removed from Debian and how OpenJDK just isn't really working for me (yet, I hope). Herein I will document progress I am making toward making the non-free Java binaries downloaded directly from Oracle work. I will update this post as I make progress.

The following applies to Java 6. I don't know what needs to change for Java 7. Is this the best way to do this? Probably not. If you know of something better, please let me know.

Get and deflate the JRE binaries
  1. Go to the Oracle Java for Linux page and follow the directions to download the *.bin (i.e., Linux self-extracting) file. (I opted not to use the RPM version even though Alien is available in Debian to install RPMs. The Java RPM is so full of stuff and Alien is so less than 100% reliable that I didn't want to risk messing up my system.)
  2. As root, make a directory /opt/java
  3. Copy the *.bin you downloaded above into /opt/java and issue the following commands in a terminal (as root):
    # chown root:root {name-of-the-file-you-downloaded}
    # chmod a+x {name-of-the-file-you-downloaded}
    # ./{name-of-the-file-you-downloaded}
    The first one makes sure the file is owned by root, the second one makes the file executable, and the third one executes the file -- which deflates all the Oracle Java goodness into a directory called something like jre1.6.0_xx.
  4. Create a link called jre to the directory jre1.6.0_xx (or whatever) created above. This link will make updating the binaries much easier in the future. Use this link from now on to reference files in the jre1.6.0_xx (or whatever) directory.
Point the system to the new java executable
  1. Use your favorite method to install the galternatives package from the repositories. Galternatives gives you a nice GUI interface to the "Debian alternatives" system. We will need this to override the default system alternative you may already have for the java command.
  2. Open Galternatives and look for an entry in the "Alternatives" column on the left called "java". If you don't have a "java" entry, skip the next step.
  3. When you click on the "java" entry in Galternatives, the right pane should show you a list of available alternatives that you can set your system to use as the java command. Click the "Add" button on the bottom of the window and navigate to /opt/java/jre/bin/java . After you close the file browser dialog and return to the main window, click the radio button next to the /opt/java/jre/bin/java choice to tell the system that you want to use that java to handle java commands. Skip the next step and go directly to Testing.
  4. Do this step only if you did NOT have a "java" entry in Galternatives. Create a soft link from /usr/bin/java to /opt/java/jre/bin/java . (Changing the /usr/bin/java link when it has been set by the Debian alternatives system may give you a whole lot of future pain, so mind the caution!)
Testing
  1. Open a terminal and enter the command
    $ java -version
    The resulting output should give you a version number that matches what you downloaded above. If it doesn't, something went wrong.
You should now have a system that will run Java apps using the Oracle JDK you downloaded. Applets will not yet be working. We'll tackle that next.

Configure browser plugin
The directions for installing the browser plugin given by Oracle may leave some browsers out in the cold. I put together a script that creates a link to the plugin in all the locations that the last debian sun-java1.6 plugin package did.
  1. Download the script from here.
  2. Look it over to make sure it's configured correctly for your system.
  3. In a terminal (as root):
    # chmod a+x {name-of-the-file-you-downloaded}

    # ./{name-of-the-file-you-downloaded}
  4. Restart your browser and test that applets are working by going to the Oracle Java test page.
I tested the above with Iceweasel, Chrome, and Opera and they all worked as expected. On one of my machines, I had to re-enable the plugin in Chrome. To do that, enter chrome://plugins in the URL bar and the rest should be obvious.

If you study the script carefully, you will see that there are commented-out bits that you can use to remove the links it created. Lemme know if you need to do this but can't figure out what to do.

Configure Webstart
In Iceweasel and Opera, configuring Java Web Start for me was as simple as going to a page that had a Java Web Start app in it (e.g., this one), clicking on it, and then directing the browser to use /opt/java/jre/bin/javaws.

I was able to get Chrome to work in a roundabout way by first downloading a *.jnlp file and then using my file manager (Thunar in Xfce) to tell it to open *.jnlp files with javaws by default. After that, in Chrome I downloaded a *.jnlp file again and then (still in in Chrome) I clicked the arrow next to the file name and selected "Always open files of this type." There may be a better way to do this.

Put the Java binaries on the PATH
There's a bunch of execuatables in /opt/java/jre/bin that will make life a lot easier if they are on the PATH. To that end,
  1. As root, copy the file found here to /etc/profile.d/oracle_java_mfk.sh  (the actual name isn't really that important as long as it ends with .sh).
  2. Reboot.
On reboot, the executables in /opt/java/jre/bin will be available on the command line, which is as God, er, Oracle, intended. Feel free to test by opening a terminal and entering
$ which keytool
The result should point to the executable in /opt/java/jre/bin. If doing this spooks you (it is, after all, a system file), you can still get by without. But you will have to launch things like the Java Control Panel and other goodies from the /opt/java/jre/bin directory rather than as a command or by using one of the convenient GUI desktop entries (discussed below).

Install desktop files
There are a bunch of files in /opt/java/jre/lib/desktop that help to integrate the JRE into you system. These aren't critical, but they're probably nice to have. At the very least, they add a menu entry to start the Control Panel. I have written a script to install these files here.

Note that this script copies stuff into your system, which means 1. it will clobber resources you might already have (which you shouldn't if you completely removed the Wheezy sun-java6 packages) and 2. it makes uninstalling a tedious process of manually deleting the files that were copied over. Don't delete the directories mentioned in the scripts! There is probably stuff in those directories that your system needs. Instead, look at the files in the directories and subdirectories in /opt/java/jre/lib/desktop and delete each of those manually. (For more info on MIME stuff see http://developer.gnome.org/integration-guide/stable/mime.html.en).

Install Java fonts
Oracle Java includes a group of fonts from the Lucida family of typefaces. Yup, I've got another script for installing those, and you'll find it here. More than you ever wanted to know about fonts in Debian is here.

Updating the system
When a new version of the JRE is released, updating should really be just a matter of deleting everything in /opt/java and repeating the steps in the Get and deflate the JRE binaries section. If you want to be really thorough though, you'll also want to repeat Install desktop files and Install Java fonts sections.

The somewhat massive gorilla in the room now is, "How do you know if an update is available." Sadly, for this I have no brilliant solution. That means you should probably check the Java SE Downloads page occasionally to see if one has been released.

Update 2011-11-26: Added Install desktop files section. Added the Install Java fonts section.
Update 2011-11-27: Changed path to javaws executable and updates info on getting Webstart to work with Chrome. Added comments about (not) getting notified of updates in Updating the system. Added how to configure plugins in Chrome to Configure browser plugin.

Debian drops Oracle Java

I am sorta bummed that the Debian devs have decided to ditch Oracle Java. At the present time, there are no sun-java6 packages in Wheezy, and sid has old builds (for some reason). It is unclear to me whether Oracle Java was dropped because of licensing issues or because it has unresolvable security issues. I assume the former even though the bug report gives the impression of the latter.

In theory, the free OpenJDK packages provide a sufficiently stable and functional alternative to Oracle Java. But if you read up enough on this, you'll find that people are still having issues with OpenJDK. I am among them. In particular, I am finding OpenJDK provides noticeably slower performance than Oracle Java. With things like Processing and FreeRouting, the difference is quite noticable.

Of course I would prefer to use the free OpenJDK over the proprietary Oracle Java -- but OpenJDK just doesn't seem up to the job yet, at least not for the kinds of things I need Java for. There is a bit of a vicious cycle here -- OpenJDK is unlikely to get the kinds of optimizations it needs unless people are actually using it and bump into its limitations. To this end, I will happily take a bit of a performance hit or other inconvenience, but not as much as I am seeing.

I am now trying to rip out all the sun-java6 and OpenJDK stuff on one of my computers and install the full-fledged Oracle Java experience (JRE, browser plugin, Webstart, and JDK) from the Oracle site. I'm working with the JRE only at the moment, and it's proving to be a pretty painful process. More later if I succeed.