« Thousands of Years of Technological Progress Lead Up to This Moment | Main | Falling Trees, Downed Power Lines, and Calling 911 After Midnight »

Native Java on FreeBSD

Owing to the fact that my master's project is written in java, I've decided to bite the bullet and install native java on FreeBSD.

This is a more complicated business than you might expect thanks to Sun's licensing restrictions. Basically, Sun doesn't develop for FreeBSD anymore. They leave that to the FreeBSD project, allowing FreeBSD developers to download the code, make the necessary patches and install it on FreeBSD. This is good. What's not quite so good is that the licensing does not allow them to distribute the resulting binaries. Thus, you can't download a working JDK (which would allow you to write java programs) or even just a JRE (allowing you to use java programs).

This is okay bearing in mind that if there's one thing FreeBSD is good at it's distributing and compiling programs from source with minimal hassle. FreeBSD just downloads the necessary programs and libraries automatically after you type "make install clean" into the appropriate directory.

Except... Thanks to Sun's licensing issues, FreeBSD can't just download the necessary stuff automatically. You have to do it manually. This is not an incredible hassle, but it does make things more complicated than it needs to be.

So... here's what you need to get java working on FreeBSD:

1. The ports collection. You should have downloaded this during installation, but you can still do it now.
2. Ideally (but optionally), the source code for everything on your computer. You could have done this during installation too. This is just worth doing if you're going to use ports in general--not a real requirement.

So you go to a JDK directory (for example: cd /usr/ports/java/jdk14) and type "make install clean" and you discover you need:
3. the patch for the current version of this JDK. You download it from here.
4. Then you'll discover that you need a binary from Sun. They'll give you a link to it in the error message when you've uselessly tried to compile.
5. Then you'll discover (after another fruitless compile) that you need the actual source code for the JDK in question.
6. After that, you'll try again and discover that you now need to download a linux binary of a JDK. As ever, the link is in the error message.

Once all these files are in "/usr/ports/distfiles," you will finally have a halfway decent chance of getting java working.

As I understand it, there is a project that attempts to minimize the hassle of doing all this while simultaneously complying with licensing restrictions. Unfortunately, it only applies to JDK 1.3 at this point. Bearing in mind that my project depends on having JDK 1.4 at minimum, this is not an option.

Sigh.

On the bright side, JDK 1.4.2 is happily compiling in the background as I write this. For the moment life is good--assuming I don't have to download anything else.